-
-
Save adamrights/7666141 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // add a new object | |
| var type = 'note'; | |
| var attributes = {color: 'red'}; | |
| store.add(type, attributes) | |
| .done(function (newObject) {}); | |
| .fail(function (error) {}); | |
| // update an existing object | |
| var type = 'note'; | |
| var id = 'abc4567'; | |
| var update = {size: 2}; | |
| store.update(type, id, update) | |
| .done(function (updatedObject) {}); | |
| // find one object | |
| var type = 'note'; | |
| var id = 'abc4567'; | |
| store.find(type, id) | |
| .done(function (object) {}); | |
| // Load all objects | |
| store.findAll() | |
| .done(function (objects) {}); | |
| // Load all objects from one type | |
| var type = 'note'; | |
| store.findAll(type) | |
| .done(function (objects) {}); | |
| // remove an existing object | |
| var type = 'note'; | |
| var id = 'abc4567'; | |
| store.remove(type, id) | |
| .done(function (removedObject) {}); | |
| // EVENTS | |
| // listen to store events | |
| store.on('add', function (newObject) {}); | |
| // new doc created | |
| store.on('add', function (newObject) {}); | |
| // existing doc updated | |
| store.on('update', function (updatedObject) {}); | |
| // doc removed | |
| store.on('remove', function (removedObject) {}); | |
| // any of the events above | |
| store.on('change', function (event, changedObject) {}); | |
| // all listeners can be filtered by type | |
| store.on('add:note', function (newObject) {}); | |
| store.on('update:note', function (updatedObject) {}); | |
| store.on('remove:note', function (removedObject) {}); | |
| store.on('change:note', function (event, changedObject) {}); | |
| // ... and by type and id | |
| store.on('update:note:uuid123', function (updatedObject) {}); | |
| store.on('remove:note:uuid123', function (removedObject) {}); | |
| store.on('change:note:uuid123', function (event, changedObject) {}); | |
| // ... react on changes coming from remote | |
| store.on('add:note', function (newObject, options) { | |
| if (options.remote) { | |
| // do something wit | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment