HCJ provides a stream library used to pass dimensions from parents to children and minimum dimensions from children to parents.
A Stream T is defined as an object with two properties:
• nbsp;lastValue :: T nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp;
nbsp; nbsp;
The most recent data point.
• nbsp;listeners :: [T - gt; ()]
nbsp; nbsp;
Functions that are run whenever there is a new data point.
Broadly speaking, there are two ways to define HCJ streams. The first is with stream.create or stream.once. Streams created with these methods receive new data points whenever you push to them (see stream.push and stream.pushAll).
The second way is to apply an operation to existing streams. stream.map and stream.reduce are the most common such operations. Streams defined this way generally receive new values whenever their input streams receive new values.
HCJ streams are optimized for communicating dimensions between parents and children, not for aggregating data. If you push a value through a stream multiple times, it is only guaranteed to be handled the first time. If you push multiple values through a stream synchronously, only the last one is guaranteed to be handled.
To run an action after all stream operations have settled, use hcj.stream.defer instead of setTimeout. To push to a stream after all synchronous actions are complete, use hcj.stream.next instead of setTimeout so that hcj.stream.defer knows to wait for your pushes.
Stream Methods
These are the stream functions included with HCJ. All are properties of the window.hcj.stream object:
Combine
combine :: ([Stream a, Stream b, ...] , (a, b, ...) - gt; x) - gt; Stream x
Takes an array of streams, and a function. Applies the function to the latest values from all input streams, updating output stream whenever any input changes.
CombineInto
combineInto :: ([Stream a, Stream b, ...] , (a, b, ...) - gt; x , Stream x) - gt; ()
Like combine, but instead of returning a stream, pushes all values into an existing stream created with create or once.
CombineObject
combineObject :: {x: Stream a, y: Stream b, ...} - gt; Stream {x: a, y: b, ...}
Takes an object whose properties are streams, returns a stream of objects.
Create
create :: () - gt; Stream a
Creates a stream with no initial value.
Debounce
debounce :: (Stream a , Number) - gt; Stream a
Pushes values from its input stream unmodified to its output stream, no more frequently than the given number of milliseconds.
Delay
delay :: Stream a - gt; Number - gt; Stream a
Pushes values unmodified to its output stream after waiting the given number of milliseconds.
Filter
filter :: (Stream a , a - gt; Bool) - gt; Stream a
Takes a stream and a predicate. Returns a stream that includes only the values for which the predicate is truthy.
FromPromise
fromPromise :: (Promise a , a?) - gt; Stream a
Takes a promise, and an optional initial value. Returns a stream that receives a value when the promise resolves, and initialized with the initial value if one is provided.
Map
map :: (Stream a , a - gt; b) - gt; Stream b
Applies a function to each point of a stream.
Once
once :: a - gt; Stream a
Creates a stream with an initial value.
OnValue
onValue :: (Stream a , a - gt; ()) - gt; ()
Like map but does not return a stream.
Prop
prop :: (Stream {x: a, ...} , "x") - gt; Stream a
Maps over a stream of objects, accessing the specified key.
Push
push : (Stream a , a) - gt; ()
Pushes a value into an existing stream created with create or once.
PushAll
pushAll : (Stream a , Stream a) - gt; ()
Pushes all values from one stream onto an existing stream. Source stream is first, target second.
Reduce
reduce : (Stream a , b - gt; a - gt; b , b) - gt; Stream b
Applies a function to each data point of a stream, keeping a running total.
SplitObject
splitObject : {x: a, y: b, ...} - gt; {x: Stream a, y: Stream a, ...}
Takes an object, and returns an object whose values are a streams initialized with the values from the input object.
Defined Streams
HCJ defines some streams that may be useful in application code. These streams are all properties of the hcj.viewport object.
Height
hcj.viewport.heightS gives the current height of the window in pixels.
Scroll
hcj.viewport.scrollS gives the current Y scroll position.
Width and FullWidth
hcj.viewport.widthS gives the width of the window in pixels, minus the width of the vertical scrollbar if present.
hcj.viewport.fullWidthS gives the full width of the window in pixels, including the vertical scrollbar if present.
HCJ.JS
Home
0. Introduction
1. Hello World
Tutorial
Examples
Components
Layouts
Styles
Colors
Streams
Custom Components
Custom Layouts
API
HCJ.JS
Home
Tutorial
0. Introduction
1. Hello World
Examples
API
Components
Layouts
Styles
Colors
Streams
Custom Components
Custom Layouts
Menu