Comments (4)
No, there is no way to get current value of property.
If you really need to, you can do something like this:
var notSet = {};
var value = notSet;
var setVal = function(x) {value = x};
obs.onValue(setVal).offValue(setVal);
if (value === notSet) {
// property has no current value yet
} else {
// here it is, current value in the `value` variable
}
But don't use ._current
it may contain internal special value, or be outdated (updates on activation).
To check if an observable a property, just do obs instanceof Kefir.Property
from kefir.
It looks like dirty solution. Also it's not clear that onValue
on Property
calls handler synchronously (and will be sync in future).
Is it possible to add this method to api (getCurrent)? Seems like it's very easy to add now.
Property - is smth that contains value. Do I understand correctly? So, there is value, but we can't get it. A little curiously.
from kefir.
It looks dirty because it not right thing to do. It not very easy to add such method to the API, but possible (using a hack like one above). But I don't think that method should be in API (I agree with Bacon.js on this https://github.com/baconjs/bacon.js/wiki/FAQ#how-do-i-get-the-latest-value-of-a-property)
from kefir.
A little more inside on the subject.
As I mentioned before, ._current
not always contain current value of a property. It might be outdated and gets updated when you add first subscriber. So first (and all the rest) subscribers always gets correct current value.
This works that way to make possible get current value from any source. For example one can do something like this:
var inputValue = Kefir.fromBinder(function(emitter) {
// the current value of the property will come from this line
emitter.emit($input.val());
function emitVal() {emitter.emit($input.val())}
$input.on('change', emitVal);
return function() {
$input.off('change', emitVal);
}
}).toProperty();
I can't remember now, but there is also another reasons why it works that way. Mostly it important on some edge cases. In early versions of Kefir there was method .getCurrent()
, and it was used internally in all places where one observable subscribes to another, but it didn't go well.
Closing it now, I hope I answered your question :)
from kefir.
Related Issues (20)
- KefirJS and WebSockets HOT 4
- Only `sampledBy` is past tense
- Current state policies HOT 2
- Idea: Usable as AsycInterator
- Proposal to add `fromProperty` static function HOT 15
- Static Land interop `Observable` definition is wrong HOT 5
- Shouldn't a property only emit on "new values"? Proposing `onChange()` HOT 1
- Missing type for `unplug`
- Maintain TypeScript types? HOT 4
- Stop bundling `symbol-observable`
- TypeError: this._emitValue is not a function HOT 1
- Make subscription available inside callback HOT 8
- A big "Thank You" to Kefir developers HOT 1
- How to import Kefir within Rollup library HOT 3
- groupBy function HOT 8
- flatMapConcat should work when a spawned observable ends synchronously on activation
- Add documentation to "Kefir.pool" as "Rx.Subject equivalent" HOT 2
- Synchronous emit in flush method of debounce produces incorrect result HOT 8
- Is it possible to not activate a staled observable when reactivating flatMapLatest? HOT 8
- Russian docs translate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kefir.