Closed a-s-o closed 9 years ago
Usage
let day = Kefir.model('monday');
day('tuesday');
day.onValue(value => console.log(value));
day('wednesday');
// Logs
// => tuesday
// => wednesday
console.log( day() ) //=> 'wednesday'
day('thursday') // set a value
console.log( day() ) //=> 'thursday'
Important properties:
I don't have any plans of implementing Model at the moment. I think it could be done as a separate lib/plugin.
Regarding your implementation, you shouldn't use private methods/properties that start from _
. It's not part of the public API and can be changed at any time.
Okay, thanks for the info; that is good to know. I will keep updating the gist linked above further and hopefully someone else can make use of it.
In terms of the private _
methods, I need a way to arbitrarily push values down the underlying observable so that was the only way I was able to find out. Is there something similar to Bacon's bus.push()
in Kefir or what would be the functional equivalent?
My other idea was to create a pool and then plug
a single value stream into that each time a value is set
on the model but that seems a little round-about to me and I also couldn't find an equivalent to bacon.once()
in Kefir
Thanks
In terms of the private _ methods, I need a way to arbitrarily push values down the underlying observable so that was the only way I was able to find out. Is there something similar to Bacon's bus.push() in Kefir or what would be the functional equivalent?
It was made a bit harder on purpose, because was considered an antipattern (see #88). But in your case it's ok to arbitrarily push values to a stream, and there are at least two ways of doing that: You can create a stream using Kefir.stream()
and extract emitter from it as shown here. Also, as you mentioned, you can create a pool, and plug Kefrir.constant(x)
to it.
P.S. I'll probably won't be able to answer to issues for a whille (until end of the month), but if you'll have other questions please keep posting, and I'll answer when be able to.
Okay, thanks for those references and your help. I will close the issue for now and post back if I have any other questions. I will update the original gist with a better implementation using the public methods as you suggested for future reference.
Hello, I would like to know whether Kefir.model is still going to be implemented. I saw that there was some discussion in #43. I am presently using the following solution:
Please see gist at: https://gist.github.com/a-s-o/0911caf8f29d2195acef
Please feel free to point out any obvious problems here. I just started with these these and would like your feedback in spotting any issues.
Thanks