GithubHelp home page GithubHelp logo

typicaljoe / taffydb Goto Github PK

View Code? Open in Web Editor NEW
2.2K 2.2K 287.0 345 KB

TaffyDB - an open source JavaScript Database for your browser

Home Page: http://taffydb.com

License: MIT License

JavaScript 100.00%

taffydb's People

Contributors

aisera-mikowski avatar beumsk avatar danielruf avatar josecolella avatar leaanthony avatar ltullman avatar mcwhittemore avatar mmikowski avatar moshen avatar noyesa avatar snapadmin avatar theinnerparty avatar typicaljoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

taffydb's Issues

From row object to index

Hello there,

I wonder, is it possible to get the index of the row object?
Something like this:

var db = TAFFY([.....]);
var row = db("T000008R000003");
var index = db.indexOf(row); // for example 3

thanks

TAFFY crashes at not default filters with not existing column in records

It crashes when we try to use custom filters (left, right, has, hasAll, etc..), thats uses methods on not existing filter column.
Example:

var cities = TAFFY([
    {name:"New York",state:"WA"},
    {name:"Las Vegas",state:"NV"},
    {name:"Boston",state:"MA"}
    ]);

cities({columnNotExists:{'left':'Hello'}})
  .each(function (r) {
    console.log(r)
  }
);

Throws error in filter-related method.

Small fix to it:

// push a function onto the filter collection to do the matching
matchFunc = function () {
  // get the value from the record
  var
    mvalue   = this[i],
    eqeq     = '==',
    bangeq   = '!=',
    eqeqeq   = '===',
    lt   = '<',
    gt   = '>',
    lteq   = '<=',
    gteq   = '>=',
    bangeqeq = '!==',
    r
    ;

//<<<<<FIX THERE
  if (undefined === mvalue) {
    return false;
  }
//<<<<<END FIX THERE
....

Do has and hasAll work?

How are has and hasAll supposed to work?

In case of
var db = TAFFY([ {"author": "name", "title": "anything", "keywords": ["a", "b"]}, {"author": "name", "title": "anything", "keywords": []} ]);

Both rows are returned for db({keywords: {has: 'a'}}) and for db({keywords: {hasAll: ['a', 'b']}}). Is this normal? How can I query this array?

Caching bug

Caching is broken for some cases where the only difference is the content of a regular expression. Example:

{
name: 'James'
types: ['x','y','z']
}

The other thing is a broken caching key with regex:

taffyDB({name:{regex:/James/}}).count() === 1;
taffyDB({name:{regex:/Anything else at this point/}}).count() === 1;
taffyDB({name:{regex:/Will always work/}}).count() === 1;

Because:
JSON.stringify(/Anything/) === JSON.stringify(/Everything/) &&
JSON.stringify(/Everything/) === '{}'

As JSON.stringify is what's used for the cache key this won't work for regex queries.

I have a fix for it in my fork and submitted a pull request.

why each function have a not row data ?

compTable().each(function(r){
console.log(r);
html+='

  • '+r.compName+'移除
  • ';
    });
    the console print :
    Object {___id: "T000002R000002", ___s: true}
    Object {compRelMainId: "1", compMainId: "1", compName: "部件1", compVolume: "28cm x 47cm x29", compWeight: ""…}

    Object {compRelMainId: "2", compMainId: "1", compName: "部件1", compVolume: "28cm x 47cm x29", compWeight: ""…}

    remove record

    How to remove record??
    I do the following :

    if(notes.store('notes')){
    notes({note_id:$id}).remove();
    }
    this did not work

    Using a different function to Sort data

    Hello,

    Is there a way to pass another function for sorting data?

    I mean: now you are using the standard native function Array.prototype.sort, but this can cause browser loops (Chrome/Firefox) if there are a lot of data with the same value.

    So, can we set another function?
    Something like this

    var db = TAFFY([.....])
    db.settings({ sortFunction: function(data){} });

    Thanks

    Update fails: Uncaught TypeError: Cannot read property 'xxx' of undefined

    ID array contains the following ids for example: T000004R000002, T000004R000003, T000004R000004...

    When updating after a query, id passed to DBI.update is T000005R000002 ... which doesn't exists in the ID array.
    This then raises an error:
    Uncaught TypeError: Cannot read property 'xxx' of undefined

    I believe the problem is not in the update but in the query which changes the ids at some point I guess.

    I've got a lot of updates working correctly and I do not see what's different in this case.

    How to perform "or" queries?

    Hello,

    I'd like to perform or query, like this:

    var db = TAFFY([...]);
    db( {name: "my name 1"}, {name: "my name 2"});

    In this case I'd like to have all records that have "my name 1" and all records that have "my name 2".

    Thanks

    Add onPostUpdate() method

    I had a need for an onPostUpdate method. I had to add a couple of extra DBI.dm(new Date()); calls because my onPostUpdate methods where calling methods on other taffydb instances (which might then call a method on the first instance) and I didn't want any stale data returned.

    Index: taffy.js

    --- taffy.js (revision 40)
    +++ taffy.js (working copy)
    @@ -748,7 +748,7 @@
    // * Returns: An array of all matching records
    // ****************************************
    run.call( this );

    •  return $.extend(true, [], this.context().results);
      
    •     return this.context().results;
      

      });

      API.extend( 'stringify', function () {
      @@ -1120,6 +1120,7 @@
      template : false,
      onInsert : false,
      onUpdate : false,

    •      onPostUpdate      : false,
         onRemove          : false,
         onDBChange        : false,
         storageName       : false,
      

      @@ -1272,6 +1273,7 @@
      TOb.push( v );

           ID[v.___id] = TOb.length - 1;
      
    •        DBI.dm( new Date() );
           if ( settings.onInsert &&
             (runEvent || TAFFY.isUndefined( runEvent )) )
           {
      

      @@ -1330,6 +1332,12 @@
      }
      TOb[ID[id]] = nr;
      DBI.dm( new Date() );

    •        if ( settings.onPostUpdate &&
      
    •          (runEvent || TAFFY.isUndefined( runEvent )) )
      
    •        {
      
    •          settings.onPostUpdate.call( nr, tc );
      
    •        }
      
    •        DBI.dm( new Date() );
         }
       },
       remove       : function ( id ) {
      

    localeCompare in logical sort and order

    Currently taffydb doesn't order properly characters with accents:

    var db = TAFFY([{name:"a"},{name:"â"},{name:"Â"},{name:"A"},{name:"Z"},{name:"z"}]);
    db().order("name logical").select("name")
    // ["a", "A", "Z", "z", "â", "Â"]
    // correct order in most locales: ["a", "â", "Â", "A", "Z", "z"]
    

    That result could be achieved by use of the String#localeCompare javascript function:

    "A".localeCompare("â", "generic", {sensitivity:"base"})
    // 0
    

    The locale parameter could maybe be specified as an option to .order() and .sort().

    onUpdate always running when calling update()

    I don't believe the taffydb behaviour matches the following example from the documentation. onUpdate is always getting called.

    db().update({column:"value"},false); // update but do not call onUpdate event
    

    I believe line 670 of version 2.6 should be:

    runEvent = arg1;
    

    TaffyDB queries/filters don't work in ExtendScript

    ExtendScript is Adobe's take on Ecma3 which allows you to write application for CS programs.

    TaffyDB runs without errors after implementing the JSON library and changing if ( ! TAFFY ){ into if ( typeof TAFFY !== 'function' ){

    However, the implementation doesn't allow me to run queries and filters. Here are the results from the test case:

    by_city: 
     ===================
    [
        {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active","___id":"T000002R000002","___s":true},
        {"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active","___id":"T000002R000003","___s":true},
        {"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active","___id":"T000002R000004","___s":true},
        {"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active","___id":"T000002R000005","___s":true}
    ]
    
    
    by_id: 
     ===================
    [
        {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active","___id":"T000002R000002","___s":true},
        {"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active","___id":"T000002R000003","___s":true},
        {"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active","___id":"T000002R000004","___s":true},
        {"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active","___id":"T000002R000005","___s":true}
    ]
    
    
    by_id_f: 
     ===================
    [
        {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active","___id":"T000002R000002","___s":true},
        {"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active","___id":"T000002R000003","___s":true},
        {"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active","___id":"T000002R000004","___s":true},
        {"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active","___id":"T000002R000005","___s":true}
    ]
    
    
    by_name: 
     ===================
    [
        {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active","___id":"T000002R000002","___s":true},
        {"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active","___id":"T000002R000003","___s":true},
        {"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active","___id":"T000002R000004","___s":true},
        {"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active","___id":"T000002R000005","___s":true}
    ]
    
    
    kelly_by_id: 
     ===================
    {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active","___id":"T000002R000002","___s":true}
    
    
    kelly_last_name: 
     ===================
    "Smith"
    
    
    id_list: 
     ===================
    [1,2,3,4]
    
    
    city_list: 
     ===================
    ["Seattle, WA","Dallas, TX","Washington, D.C."]
    
    
    filter_list: 
     ===================
    [
        {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active","___id":"T000002R000002","___s":true},
        {"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active","___id":"T000002R000003","___s":true},
        {"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active","___id":"T000002R000004","___s":true},
        {"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active","___id":"T000002R000005","___s":true}
    ]
    
    
    Example filter bug - rows changed without using .update() will filter by their original values. 
    We expect 0 rows, but get 2... 
    [object Object],[object Object],[object Object],[object Object]
    ...even though the city has changed in the collection.
    [object Object],[object Object],[object Object],[object Object]
    
    Example filter when .update() is used.
    now we get the correct response (0 rows) ...
    [object Object],[object Object],[object Object],[object Object]
    [object Object],[object Object],[object Object],[object Object]
    ... that reflects the taffy collection.

    Can anyone tell me what the possible culprit might be or make a suggestion on how I might try to solve this?

    Tnx!

    db(id).update() does not store

    if you store db using db().store(),

    the update method won't work (auto synchronize to localStorage).

    The older version works well

    not support IE 7 ?

    the code : JSON.stringify
    IE 7 not support this native method,how can I fix it?

    Change db.merge() args order or pass it an option object

    Hi, I literally fell in love with your framework!!!

    I have one suggestion though. when using .merge() is annoying to have to redeclare the 'key' arg to 'id' to set up the event handler to true. I think that it's more common in real cases to set up the event handler than to use a different key for merging than 'id'.

    But of course this could be a personal point of view. So one more general solution could be to pass option via an object with defaults {key: 'id', event: 'false'} to be merged with the one passed by the user.
    I usually appreciate this solution whenever there are more than 3 args in a function.

    What do think about it?

    mispelling

    line 1772 taffy.js, comare should be compare. just fyi

    Internet Explorer 8 (IE8) compatibility and performance

    Hello :)

    I am searching for a solution to handling of around 100,000 objects in the browser, and it should operate on IE8 per customer requirements.

    You mention robust browser support but no specific information about IE8. So I am posting this issue.

    So how well and how fast does it work on IE8?

    Thank you.

    Documentation incorrect

    On the "working with data" page on the site, it looks like there is an error...

    db().last("balance"); // returns the sum of the "balance" column.

    should be be

    db().sum("balance"); // returns the sum of the "balance" column.

    Change of a js-object property automatically changes record in Taffy instance

    Hi Ian,

    I am using TaffyDB with node.js and first of all: you did a great job with TaffyDB. Very fast and extremely cool.

    I found a strange behaviour and I am not sure whether this is a bug or a feature in TaffyDB ;) Or maybe I have a missunderstanding of JavaScript features.

    Here is some short code:

    //create DB
    var db = new TAFFY();
    //db.settings({cacheSize:0});
    //insert one record:
    db.insert({name:'Test',category:'Test'});
    //"search" for first record
    var firstRecord = db().filter({'name':'Test'}).first();
    console.log("Name: " +firstRecord.name); // returns "Name: Test" -> ok
    
    //change the name property of the record to "side effect"
    firstRecord.name = "side effect";
    //this is immediately written to TaffyDB, why ? I did not say update.
    
    //"search" for the record again:
    var secondObject= db({'category':'Test'}).first();
    console.log("Name: " +secondObject.name); // returns "Name: side effect" -> not ok?! Should be Test.

    My workaround is to clone the returned record into a new javascript object to get rid of the direct connection to Taffy, so this code works fine, but thats kind of a hack.

    Thanks in advance for any answer to this issue, greetings from Germany
    Gunnar

    B.T.W: I hope that TaffyDB is getting more attention by the time nodejs gets really production stable ;-)

    How about bower support?

    Hi!

    Great work with taffydb. I'm planing to use it for a single page app that will load the whole database on startup (it's not that big).

    I'd love to see bower support since I'm using yeoman and with that bower. It seems fairly easy to add a github js-project to bower but it needs to conform to some standards. I think the userbase of taffydb could see an increase if taffy was added to the bower repository. Do a search on bower: http://sindresorhus.com/bower-components/ for database and not many hits will show.

    If you think it's a good idea but don't have the time or interest to implement the changes and registering your library with bower please let me know, I'll do my best to produce a pull request or perhaps just register a fork of your repo (which will give me a world of hurt since I'll need to merge your updates).

    Regards

    Emil

    db.store inconsistent with documentation

    Hi, I was reading the document to check the API.

    db.store() says it returns a boolean. But when I checked the source code it return the root where it should return "r".

    I think the change might be for the chaining reason. But, is it possible to have a flag to say that localStorage is available?

    Thanks.

    Cannot able to filter data if key starts with is_

    If data is something like

          var friendList = [
                            {attributes:{is_trusted:"false", trusted_status: "false"},"gender":"M","first":"John","last":"Smith",
                                "city":"Seattle, WA","status":"Active"},
                            {"id":2,"gender":"F","first":"Kelly","last":"Ruth",
                                "city":"Dallas, TX","status":"Active"},
                            {"id":3,"gender":"M","first":"Jeff","last":"Stevenson",
                                "city":"Washington, D.C.","status":"Active"},
                            {"id":4,"gender":"F","first":"Jennifer","last":"Gill",
                                "city":"Seattle, WA","status":"Active"}  
                        ];
          var friend_db = TAFFY(friendList);
    
          console.log(friend_db({ attributes : {is_trusted:"false"}}).get()); // Not working          
          console.log(friend_db({ attributes : {trusted_status:"false"}}).get()); // Works
    

    More levels in subqueries

    It's posible that we can made subqueries like the next example?

    var newsfeed = TAFFY([
    {
    "id":1,
    "user":"kmart77",
    "stars":3,
    "telphones":[ { 'tel_id': 1,
    "number": 000000},
    { 'tel_id': 2,
    "number": 111111}]
    ])

    newsfeed({ telphones: { "tel_id": 1 } })

    Inconsistency in queries and subqueries?

    my english is poor, so an example:

    var db = TAFFY(
    [{col1:"val1",col2:"val21",col3:"val31"},
    {col1:"val1",col2:"val22",col3:"val32"},
    {col1:"val1",col2:"val23",col3:"val31"},
    {col1:"val1",col2:"val24",col3:"val32"}])

    alpha = db({col1:"val1"})
    //alert(alpha.select("col2"))
    beta = alpha.filter({col3:"val31"}).select("col2")
    alpha.get()

    After alpha.get(), I see (I removed the __id and __s keys):
    [{col1:"val1", col2:"val21", col3:"val31"}, {col1:"val1", col2:"val23", col3:"val31"}]
    But if I uncommented the alert line, I see what I always expected:
    [{col1:"val1", col2:"val21", col3:"val31"}, {col1:"val1", col2:"val22", col3:"val32"}, {col1:"val1", col2:"val23", col3:"val31"}, {col1:"val1", col2:"val24", col3:"val32"}]

    Regards, idoric.

    sum() breaks when columns are missing from some objects

    If you use sum() dataset and some objects are missing the column in question, NaN is returned. The following fixes the issue:

    --- taffy.js    (revision 131)
    +++ taffy.js    (working copy)
    @@ -788,7 +788,7 @@
           var that = this;
           each( arguments, function ( c ) {
             each( that.context().results, function ( r ) {
    -          total = total + r[c];
    +          total = total + (r[c] || 0);
             });
           });
           return total;
    

    Persistence of data

    How is the data persisted? Can this be integrated with other js storage libraries focusing localstorage or other DB options like websql and indexdb?

    Taffy DB Loop

    Hello, sorry for my english

    I have a DB :

    var articles = TAFFY([
                {title:"Title 1",content:"Content 1",favorite:"yes"},
                {title:"Title 2",content:"Content 2",favorite:"no"}                  
                          ]);
    

    I want to loop results to show like this :

    <label>  Title 1 </label>
    <p> Content 1 </p>
    <label>  Title 2 </label>
    <p> Content 2 </p>
    <label>  Title 3 </label>
    <p> Content 3 </p>
    
    

    My code :

    articles().each(function (r) {document.write("<div><label>" + r.title + "</label><p >" + r.content+ "</p></div>"                                                                  
                            )});
    

    get() not cloning results

    var db = TAFFY([{id: 1, val: "1"}, {id: 2, val: "2"}]);
    var results = db().get();
    results[0].val = "3";
    console.log(db().stringify());
    

    I would have expected the above to print (I removed the ___id and ___s keys):

    [{"id":1,"val":"1"},{"id":2,"val":"2"}]

    But instead it prints:

    [{"id":1,"val":"3"},{"id":2,"val":"2"}]

    Should taffydb clone/duplicate the data that is returned to prevent this? Changing line 751 to the following resolves the issue (at what performance hit I don't know):

    return $.extend(true, [], this.context().results);

    I imagine the same issue will also occur with first(), last() and any other method that returns an object.

    $.extend() is a jQuery method: http://api.jquery.com/jQuery.extend/

    update is noop when trying to cast values as different type

    I wanted to change a column of strings ["1.2", "2.3",...] to floats so I used:

      db().update(function(){ this.floatish = parseFloat(this.floatish); return this; });
    

    But this fails, seemingly because the following check should use strict not equals (https://github.com/typicaljoe/taffydb/blob/master/taffy.js#L1084):

    -                               if (TAFFY.isUndefined(or[i]) || or[i] != v) {
    +                               if (TAFFY.isUndefined(or[i]) || or[i] !== v) {
    

    Workaround is to put the new value a new column (or patch of course).

    Thanks for your work.

    Peace,
    David S.

    Flag to indicate initial loading of data via .store() - (Adding Trigger.io storage support)

    Hi. I've been experimenting with adding trigger.io's storage support as on mobiles, it can provide much greater storage capacity whilst falling back to localStorage if required. I've got everything working, however trigger.io's storage APIs are asynchronous, relying on callbacks for reads. What this means is that situations like this happen:

     var a = TAFFY();
     a.store( "test" );
     a.insert( { "a" : 1 } );
    
     var b = TAFFY();
     b.store( "test" );
     b().count() --> 0

    Wrapping the second part in a setTimeout function with a 2000ms delay will make it work but is not ideal. The only real situation this happens is on the initial load so I was thinking what the best way would be to flag that the initial call to .store() had actually populated the internal memory.

    Any thoughts?

    Thanks.

    'setTimeout' function does not exist in Mozilla Rhino

    It appears that when using Mozilla Rhino, the 'setTimeout' function (called at line 1225) does not exist.

    It appears that this is a 'built' in function but is not available in Rhino. Therefore, it'd be useful (i'd think) to provide a implementation of setTimeout for use in such environments, or documentation that it does not work with Rhino.

    Web Worker Support

    Does TaffyDB have any abstractions for web worker support? Chrome currently allows async access to indexdb, but you would have to create a postmessage hack for everything else.

    Create an NPM package

    Node integration is much easier with an npm package.

    It looks like all you need to do is create the package.json ( npm init), then publish to the repo (npm publish).

    I'm very much a node novice but here's a package.json start:

     {
       "author": "Ian Smith",
       "name": "taffydb",
       "description": "TaffyDB is an opensouce library that brings database features into your JavaScript applications.",
       "version": "0.0.1",
       "homepage": "http://taffydb.com/",
       "repository": {
         "type": "git",
         "url": "git://github.com/typicaljoe/taffydb.git"
       },
       "engines": {
         "node": "~0.4.12"
       },
       "dependencies": {},
       "devDependencies": {},
       "main": "taffy"
     }
    

    onUpdate event not working fine with array data type

    Hi, I'm trying to update a field in my db with an array of objects.
    The field is updated without problems in the db but the onUpdate event doesn't trigger.
    With strings / number data types the job is well done.

    This is the command I run:
    mydb("TR....").update({"prest_valor_cuota": rPrestValorCuota});

    where rPrestValorCuota is :
    [{valor: 0, prestatario: "", cuota: 0, total_cuotas: 0}]

    Why the onUpdate event does not trigger?

    Thanks

    (TAFFY is undefined. Line: 42).

    Hello,

    I am currently planning on integrating TaffyDB into a framework I'm trying to build in ExtendScript, an extension of Ecma 262 edition 3 for the Adobe CS programs. In order to get TaffyDB to work with ExtendScript, I had to change the following line:

    if ( ! TAFFY ){

    into this:

    if ( typeof TAFFY !== 'function' ){

    because it kept throwing a reference error. (TAFFY is undefined. Line: 42).

    Even though some libraries like the JSON library by Douglas Crockford for instance use this exact same technique, it says on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined that this technique is to be avoided:

    "However, this kind of technique should be avoided. JavaScript is a statically scoped language, so knowing if a variable is defined can be read by seeing whether it is defined in an enclosing context. The only exception is the global scope, but the global scope is bound to the global object, so checking the existence of a variable in the global context can be done by checking the existence of a property on the global object (using the in operator, for instance)"

    I'm not entirely sure why this technique is to be avoided, but I was hoping maybe some one could explain this to me why TAFFY uses if(! TAFFY) in stead of if( typeof TAFFY !== 'function').

    Plus, I wanted to share this so that other developers facing the same issue would know where to look. I'm really glad I finally got it working, because TaffyDB is definitely going to save me a lot of dev-time ;)

    Cheers,
    p.

    Add manual commit.

    Ill initiate a pull when I resolve my github connection. Thanks.

    //line 1138
    settings = {
    ...
    autoCommit : true,
    forcePropertyCase : null,
    cacheSize : 100,
    name : ''
    },

    //line 1237
    ...
    if ( settings.storageName && settings.autoCommit ){
    setTimeout( function () {
    localStorage.setItem( 'taffy_' + settings.storageName,
    JSON.stringify( TOb ) );
    });
    }

    //line 1654
    ...
    if ( TOb.length > 0 ){
    root.commit();
    }

    //below root.store
    ...
    root.commit = function ( n, callback ) {
    setTimeout( function () {
    localStorage.setItem( 'taffy_' + settings.storageName,
    JSON.stringify( TOb ) );
    if (callback) callback();
    });
    };

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. 📊📈🎉

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google ❤️ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.