medikoo / dbjs

In-Memory Database Engine for JavaScript
MIT License
28 stars 4 forks source link

More natural configuration of object streams #48

Open medikoo opened 8 years ago

medikoo commented 8 years ago

/cc @kamsi

Currently when we want to configure some action on when given object receives certain state, we usually build collection as e.g.

db.BusinessProcess.filterByKey('isRevisionReady', true).on(function (event) { ... });

What's painful is that usually we rewrite similar event handler which works around add, delete, batch events. It might be nicer if we can achieve same via something as:

db.BusinessProcess.stream('isRevisionReady', true).on(function (businessProcess) { .. });

This stream will also at initialization stream all objects that already match expected state.

Additional functionality would be to create a streams that are also guarded by pre-triggers, so we observe specific state change from A to B, and not just fact that object landed at given state. Very rough idea, on how it may look:

db.BusinessProcess.stream('isRevisionReady', true)
  .to('isRevisionApproved', true).on(function (businessProcess) { .. });
medikoo commented 8 years ago

It would be good to also together with that support forthcoming promise streams.

That means one can observe promises as generated by callbacks, and if there's no observer for them, they have done invoked internally.