canjs / can-simple-observable

Create an observable value.
https://canjs.com/doc/can-simple-observable.html
MIT License
3 stars 1 forks source link

Should resolver always dispatch an event? #20

Closed phillipskevin closed 6 years ago

phillipskevin commented 6 years ago

In order for the can-define value behavior to handle more use cases that streams can handle, maybe resolver should be able to resolve the same value multiple times.

I would like to be able to do something like this in order to keep the value of oddNumber as always an odd number:

    oddNumber: {
      value({ resolve, listenTo, lastSet }) {
        let lastOddNumber = 5;

        resolve(lastOddNumber);

        listenTo(lastSet, val => {
          if (val % 2 === 1) {
            lastOddNumber = +val;
          }

          resolve(lastOddNumber);
        });
      }
    }

This doesn't work because, the resolver will only dispatch an event if the underlying value changes: https://github.com/canjs/can-simple-observable/blob/42a2b69bccd01da15055f39cc8ffb1a0856b6165/resolver/resolver.js#L109

phillipskevin commented 6 years ago

Here is the example code: https://jsbin.com/nepige/1/edit?js,output

phillipskevin commented 6 years ago

This should be handled by https://github.com/canjs/can-stache-bindings/blob/master/can-stache-bindings.js#L662 without having to dispatch another event, per @justinbmeyer.

phillipskevin commented 6 years ago

Issue moved to canjs/can-stache-bindings #431 via ZenHub