import { Stream, StreamWithSend } from "./Stream"; import { Cell } from "./Cell"; import { Transaction } from "./Transaction"; import { Unit } from "./Unit"; import { Source, Vertex } from "./Vertex"; export class Operational { /** * A stream that gives the updates/steps for a {@link Cell}. *
* This is an OPERATIONAL primitive, which is not part of the main Sodium
* API. It breaks the property of non-detectability of cell steps/updates.
* The rule with this primitive is that you should only use it in functions
* that do not allow the caller to detect the cell updates.
*/
static updates(c : Cell) : Stream {
/* Don't think this is needed
const out = new StreamWithSend(null);
out.setVertex__(new Vertex("updates", 0, [
new Source(
c.getStream__().getVertex__(),
() => {
return c.getStream__().listen_(out.getVertex__(), (a : A) => {
out.send_(a);
}, false);
}
),
new Source(
c.getVertex__(),
() => {
return () => { };
}
)
]
));
return out;
*/
return c.getStream__();
}
/**
* A stream that is guaranteed to fire once in the transaction where value() is invoked, giving
* the current value of the cell, and thereafter behaves like {@link updates(Cell)},
* firing for each update/step of the cell's value.
*
* This is an OPERATIONAL primitive, which is not part of the main Sodium
* API. It breaks the property of non-detectability of cell steps/updates.
* The rule with this primitive is that you should only use it in functions
* that do not allow the caller to detect the cell updates.
*/
static value(c : Cell) : Stream {
return Transaction.run(() => {
const sSpark = new StreamWithSend