www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Reactive data

reply crimaniak <crimaniak gmail.com> writes:
I want to have reactive variables like in this example:

```
USING_REACTIVE_DOMAIN(D)

// The two words
VarSignalT<string> firstWord  = MakeVar<D>(string( "Change" ));
VarSignalT<string> secondWord = MakeVar<D>(string( "me!" ));
// ...
SignalT<string> bothWords = firstWord + string( " " ) + 
secondWord;
```

from this page: 
http://schlangster.github.io/cpp.react/tutorials/BasicSignals.html

Is this possible to make it in D with 
https://github.com/lempiji/rx ? Is there other libraries exists 
for this topic?
Mar 23 2018
parent reply lempiji <lempiji gmail.com> writes:
On Friday, 23 March 2018 at 12:59:23 UTC, crimaniak wrote:
 I want to have reactive variables like in this example:

 ```
 USING_REACTIVE_DOMAIN(D)

 // The two words
 VarSignalT<string> firstWord  = MakeVar<D>(string( "Change" ));
 VarSignalT<string> secondWord = MakeVar<D>(string( "me!" ));
 // ...
 SignalT<string> bothWords = firstWord + string( " " ) + 
 secondWord;
 ```

 from this page: 
 http://schlangster.github.io/cpp.react/tutorials/BasicSignals.html

 Is this possible to make it in D with 
 https://github.com/lempiji/rx ? Is there other libraries exists 
 for this topic?
I think that it can use combineLatest which was recently added. If using 'alias this' or 'operator overloading', might look like more original example. ----------- import rx; auto firstWord = new BehaviorSubject!string("Change"); auto secondWord = new BehaviorSubject!string("me!"); auto bothWords = new BehaviorSubject!string(""); combineLatest!((a, b) => a ~ " " ~ b)(firstWord, secondWord).doSubscribe(bothWords); writeln(bothWords.value); // Change me! firstWord.value = "TEST"; writeln(bothWords.value); // TEST me! -----------
Mar 31 2018
parent crimaniak <crimaniak gmail.com> writes:
On Saturday, 31 March 2018 at 16:08:36 UTC, lempiji wrote:

 -----------
 import rx;

 auto firstWord = new BehaviorSubject!string("Change");
 auto secondWord = new BehaviorSubject!string("me!");

 auto bothWords = new BehaviorSubject!string("");
 combineLatest!((a, b) => a ~ " " ~ b)(firstWord, 
 secondWord).doSubscribe(bothWords);

 writeln(bothWords.value); // Change me!

 firstWord.value = "TEST";
 writeln(bothWords.value); // TEST me!
 -----------
Thanks! I will play with it.
Apr 02 2018