Essentially, the reducer would specify events to bind to and a corresponding function that gets the last value, event emitted and returns the new value. Here's how fullName could be built without a getter (and https://github.com/canjs/can-define/pull/434 merged) :
The functions should be called with the last value and all arguments used to dispatch the event. This makes it possible to have a funciton like (last, event, newValue, oldValue) => {}.
Should "deep" values be supported? For example reduce: { "task.length": ()=>{} }.
How should the set values be treated? Perhaps a reserved name?
I'd like something like the following to work:
Essentially, the reducer would specify events to bind to and a corresponding function that gets the last value, event emitted and returns the new value. Here's how
fullName
could be built without agetter
(and https://github.com/canjs/can-define/pull/434 merged) :Notes / Questions
The functions should be called with the last value and all arguments used to dispatch the event. This makes it possible to have a funciton like
(last, event, newValue, oldValue) => {}
.Should "deep" values be supported? For example
reduce: { "task.length": ()=>{} }
.How should the set values be treated? Perhaps a reserved name?
Could a
get
be used as a "final" stage and avoid intermediate steps?Can these "reducers" be shared and tested somehow? Or would we need
can-reducer
for this?How to build this
We can add a reducer observable that would work like:
This can be mixed in similar to how
ResolverObservable
is here: https://github.com/canjs/can-define/blob/10d906817e238286acfcf3a1d5120232232f0983/can-define.js#L455ReducerObservable
would be a constructor function very similar in API toResolverObservable
, with the right symbols: