ProAct Class
src/js/core/pro.js:9
ProAct.js turns plain JavaScript objects into holders of reactive properties. You can define the dependencies between these objects and properties using the 'vanilla' js syntax. For example if an object should have a property 'x', that depends on its two fields 'a' and 'b', the only thing that's needed is to define a function 'x', that refers to 'this.a' and 'this.b'.
So ProAct.js can turn every vanilla JavaScript value to a set of reactive properties, and this generates a dependency graph between them. The data flow in this oriented graph is determined by its edges. So if we should receive data from the outside of this dependency system we'll need a powerful but easy to use tool to turn every user or server generated action into a data event, common to the graph.
ProAct.js can be used to define bindings, to separate views from models (mv*), for performance optimizations... It is a tool. A powerful tool for creating other, high level tools, or applications. Everything should be defined in this namespace. It can be used as P or Pro.
ProAct is powerful Functional Reactive Programming (FRP) lib too. Its streams and events
are integrated with the reactive properties mentioned above.
Everything can be described using declarative expressions.
All ProAct classes and functions are defined in this namespace.
You can use Pro
and P
instead of ProAct
too.
Item Index
Methods
- closed static
- fromCallback static
- fromEventDispatcher static
- fromInvoke static
- interval static
- interval static
- isProObject
- N
- prob static
- proxy static
- seq static
- stream static
- timeout static
Properties
- currentCaller static
- flow
- registry static
- VERSION static
Methods
closed
()
ProAct.Stream
static
Creates a closed ProAct.Stream.
Returns:
A closed ProAct.Stream instance.
fromCallback
-
callbackCaller
Creates a ProAct.Stream, which emits the result of an action that uses a callback to notify that it is finished.
This can be used to create streams from http requests for example.
Example:
var stream = ProAct.fromCallback(action);
stream.on(function (v) {
console.log(v);
});
Parameters:
-
callbackCaller
FunctionThe action that receives a callback.
Returns:
A ProAct.Stream instance.
fromEventDispatcher
-
target
-
eventType
Creates a ProAct.Stream with source an evet emitter or dispatcher, it can be used with jQuery for example for example.
Example:
var stream = ProAct.fromEventDispatcher($('.some-input'), 'keydown');
stream.on(function (e) {
console.log(e.which);
});
Parameters:
Returns:
A ProAct.Stream instance.
fromInvoke
-
interval
-
func
The fromInvoke creates a ProAct.Stream, which emits the result of the passed func argument on every interval milliseconds.
If func returns closed the stream is closed.
Example:
var stream = ProAct.fromInvoke(1000, function () { return 5; }); stream.on(function (v) { console.log(v); }); // After 1s we'll see '5' in the log, after 2s we'll see a second '5' in the log and so on...
Parameters:
Returns:
A ProAct.Stream instance.
interval
-
interval
-
value
Creates a ProAct.Stream, which emits the passed "value" over and over again at given time interval.
Example:
var stream = ProAct.interval(1000, 7); stream.on(function (v) { console.log(v); }); // This will print one number on every 1s and the numbers will be 7,7,7,7,7....
Parameters:
Returns:
A ProAct.Stream instance.
interval
-
interval
-
vals
Creates a ProAct.Stream, which emits values of the passed vals array on the passed interval.
When every value is emitted through the stream they are emitted again and again and so on...
Example:
var stream = ProAct.repeat(1000, [4, 5]); stream.on(function (v) { console.log(v); }); // This will print one number on every 1s and the numbers will be 4 5 4 5 4 5 4 5 4 5 .. and so on
Parameters:
Returns:
A ProAct.Stream instance.
isProObject
-
value
Checks if the passed value is a valid ProAct.js object or not.
ProAct.js object have a special __pro__
object that is hidden in them, which should be instance of ProAct.Core.
Parameters:
-
value
ObjectThe value to check.
Returns:
True if the value is object containing ProAct.Property instances and has a core
.
N
()
No-action or emtpy function. Represent an action that does nothing.
prob
-
object
-
meta
The ProAct.prob
method is the entry point for creating reactive values in ProAct.js
TODO More docs
Parameters:
Returns:
Reactive representation of the passed object.
proxy
-
object
-
target
-
meta
-
targetMeta
The ProAct.proxy
creates proxies or decorators to ProAct.js objects.
The decorators extend the target and can add new properties which depend on the extended ones.
Parameters:
-
object
ObjectThe object/value to make decorator to the target.
-
target
ObjectThe object to decorate.
-
meta
Object | StringMeta-data used to help in the reactive object creation for the proxy.
-
targetMeta
Object | StringMeta-data used to help in the reactive object creation for the target, if it is not reactive.
Returns:
Reactive representation of the passed object, decorating the passed target.
seq
-
interval
-
vals
Creates a ProAct.Stream, which emits values of the passed vals array on the passed interval milliseconds.
When every value is emitted through the stream it is closed.
Example:
var stream = ProAct.seq(1000, [4, 5]); stream.on(function (v) { console.log(v); }); // This will print one number on every 1s and the numbers will be 4 5 and the stream will be closed.
Parameters:
Returns:
A ProAct.Stream instance.
stream
-
[subscribe]
-
[transformations]
-
source
-
queueName
Creates a ProAct.Stream instance.
This method is capable of creating various source
streams.
For example if the method is called like that:
var stream = ProAct.stream();
A sourceless stream will be created, but it will be possible to invoke trigger*
on it:
stream.trigger(val);
stream.triggerErr(new Error());
stream.triggerClose();
The method can be called with a subscribe function too:
var stream = ProAct.stream(function (source) {
// ... logic using the source - the source is a stream, that has trigger/triggerErr/triggerClose
$('.sel').on('click.myClick', function (e) {
source.trigger(e);
});
return function () {
// unsubscribing logic
$('.sel').off('click.myClick');
};
});
So subscribe/unsubscribe to an even source can be programmed using this method.
The first argument can be a string too and if that's the case, ProAct.Stream's
fromString
method will be used for the stream construction.
Parameters:
-
[subscribe]
String | Function optionalCan be null for no subsbcribe functon, can function to be used for subscribtion to a source or can be string to use it with ProAct.Stream/fromString:method
-
[transformations]
Array optionalA list of transformation to be used on all incoming chages.
-
source
ProAct.ActorA default source of the stream, can be null.
-
queueName
StringThe name of the queue all the updates should be pushed to.
If this parameter is null/undefined the default queue of flow is used.
If this parameter is not a string it is used as the source.
Returns:
A ProAct.Stream instance.
timeout
-
timeout
-
value
Creates a ProAct.Stream, which emits the passed "value" once and then closes.
Example:
var stream = ProAct.timeout(1000, 7); stream.on(function (v) { console.log(v); }); // This will print '7' after 1s and will close.
Parameters:
Returns:
A ProAct.Stream instance.
Properties
currentCaller
Object
static
Represents the current caller of a method, the initiator of the current action.
This property does the magic when for example an ProAct.AutoProperty is called for the first time and the dependencies to the other properties are created. The current caller expects to be used in a single threaded environment.
Do not remove or modify this property manually.
Default: null
flow
ProAct.Flow
final
The ProAct.Flow instance used by ProAct's property updates by default.
It defines only one queue - the default one proq.
Override this instance if you are creating a framework or toolset over ProAct.js.
registry
ProAct.Registry
static
The ProAct.Registry instance used by ProAct's by default.
It has a ProAct.Registry.StreamProvider registered on the s namespace.
It has a ProAct.Registry.ProObjectProvider registered on the po and obj namespaces.
It has a ProAct.Registry.FunctionProvider registered on the f and l namespaces.
Override this instance or register your own providers in it to extend the ProAct.js DSL.