Internationalisation
Bundled Plugins API
go
Defines Statements to make processing of cp.rx.Observable values in ways that are more familiar to synchronous programmers.
A common activity is to perform some tasks, wait for the results and do some more work with those results.
Lets say you want to calculate the price of an item that is in US Dollars (USD) and output it in Australian Dollars (AUD). We have anItem that will return an Observable that fetches the item price, and an exchangeRate function that will fetch the current exchange rate for two currencies.
Using reactive operators, you could use the zip function to achieve this:
1
Observable.zip(
2
anItem:priceInUSD(),
3
exchangeRate("USD", "AUD")
4
)
5
:subscribe(function(price, rate)
6
print "AUD Price: ", price * rate
7
end)
Copied!
The final subscription will only be executed once both the priceInUSD() and exchangeRate(...) push a value. It will continue calling it while both keep producing values, but will complete if any of them complete.
Using the Given statement it would look like this:
1
Given(
2
anItem:priceInUSD(),
3
exchangeRate("USD", "AUD"),
4
)
5
:Now(function(price, rate)
6
print "AUD Price: ", price * rate
7
end)
Copied!
For more information on using and creating statements, see the Statements documentation.

Submodules

API Overview

API Documentation

Last modified 1mo ago
Export as PDF
Copy link