bredele / datastore

:hamster: Bloat free and flexible interface for data store and database access.
101 stars 9 forks source link

Updated event and strict mode #29

Open bredele opened 10 years ago

bredele commented 10 years ago

I added an event 'updated' which is trigerred on set, del and reset. You can choose to trigger or not this event by setting the strict mode to true:

//trigger updated
store.set('name','bredele');

//doesn't trigger updated
store.set('name','bredele', true);

It is used internally (by pipe) and is useful for some plugins. For example, the plugin mirror emit an event to the server on changes, and set its data when some data are received from the server.

store.on('updated', function(name, val) {
  socket.emit('change', name, val);
});

socket.on('change', function(name, val){
  store.set(name, val, true);
});

Without the strict node, we will send date in loop to the server (data from server - set local store and trigger change - send data to server on change).

My question is: is there a better way to prevent to send data in loop to the server?