0

First entry in the FAQ...

There is no getLatestValue method available and will not be either.

You get the value by subscribing to the stream/property (using onValue) and handling the values in your callback

What if I'm not ready for the value at the time that it arrives? Doesn't this mean I have to store a copy of it?

If you have to subscribe to a property to get its value, what is the point of properties? Why not only use streams?

My situation is that when a user presses a button, some config is updated. Else where in my code I need to read the latest config values. But this is not going to be at the same time that its changed.

Community
  • 1
  • 1
Ian Warburton
  • 13,336
  • 19
  • 85
  • 164
  • Just use a combinator for your button click stream and the config property. – Bergi Apr 03 '15 at 13:01
  • Sorry I don't understand. I have the config updating fine from a button click. Its using the value later on that I'm stuck on. – Ian Warburton Apr 03 '15 at 13:03
  • 1
    And where in your code do you need to use that config? – Bergi Apr 03 '15 at 13:04
  • After an AJAX callback. During the callback the submit button is not enabled and has different text on it. When the request completes I need to switch the text back to what the current config says. – Ian Warburton Apr 03 '15 at 13:15
  • Sounds like you need another property telling you when the ajax request is active, and combine that with config. Or a stream of "ajax request complete" events to snapshot the "current" config values, if you need that. – Bergi Apr 03 '15 at 13:22
  • I see. When the request returns it will pop out the response and I mix this event with the current config value. – Ian Warburton Apr 03 '15 at 13:23
  • The trouble with combining is now it calls the onValue at the end of the form submit when only the config changes. :) – Ian Warburton Apr 05 '15 at 19:36

1 Answers1

0

You can use property.toEventStream() to create an EventStream based on the Property where the stream contains also an event for the current value of the Property at the time this method was called.

Example:

// Config property created somewhere
var config = someStream.toProperty();

// Your behaviour depends on config
config.toEventStream().onValue(function(conf) {
    // React to config changes here
    // conf will be the "current" value on first call
});

As mentioned in comments, combining streams and properties might be more appropriate solution depending on what you are actually trying to do.

Henry Heikkinen
  • 780
  • 8
  • 8