ProAct.DSL Class
src/js/dsl/dsl.js:156
Contains implementation of the ProAct.js DSL
.
The idea of the DSL is to define ProAct.Actors and their dependencies on each other in a declarative and simple way.
The ProAct.Registry is used to store these actors.
For example if we want to have a stream configured to write in a property, it is very easy done using the DSL:
ProAct.registry.prob('val', 0, '<<(s:data)');This tells the ProAct.Registry to create a ProAct.Property with the value of zero, and to point the previously, stored 'data' stream to it.
Item Index
Methods
- defPredefined static
- optionsFromArray static
- optionsFromString static
- static
Properties
Methods
defPredefined
-
type
-
id
-
operation
Defines a new predefined function to be reused in the DSL.
For example:
ProAct.DSL.defPredefined('filter', 'enter', function (event) {
return event.keyCode === 13;
});
creates a new filtering
function, which can be used like this:
actor2 = actor1.filter('enter');
the actor2
in this case will recieve only the events with keyCode of 13
.
optionsFromArray
-
optionArray
-
[...]
Extracts DSL actions and options from an array of strings.
Example optionArray is ['map($1)', 'filter(+)', @($2)'] and it will become options object of functions and arguments to be applied on a target ProAct.Actor passed to the ProAct.DSL/run:method method.
Parameters:
Returns:
Object containing operations as fields and options(arguments) for these operations as values.
['map($1)', 'filter(+)', @($2)'] becomes:
{ mapping: {first-argument-to-this-function-after-the-optionString-arg}, filtering: ProAct.DSL.predefined.filtering['+'], on: {second-argument-to-this-function-after-the-optionString-arg} }
optionsFromString
-
optionString
-
[...]
Extracts DSL actions and options from a string.
Splits the passed optionString using separator as saparator and calls optionsFromArray on the result.
Parameters:
Returns:
Object containing operations as fields and options(arguments) for these operations as values.
'map($1)|filter(+)|@($2)' becomes:
{ mapping: {first-argument-to-this-function-after-the-optionString-arg}, filtering: ProAct.DSL.predefined.filtering['+'], on: {second-argument-to-this-function-after-the-optionString-arg} }
-
actor
-
options
-
registry
-
[...]
Configures an ProAct.Actor using the DSL passed with the options argument.
Uses the passed ProAct.Registry to read stored values from.
Parameters:
-
actor
ProAct.ActorThe target of the DSL operations.
-
options
ProAct.Actor | String | ObjectThe DSL formatted options to be used for the configuration.
If the value of this parameter is instance of ProAct.Actor it is set as a source to the target actor.
If the value ot this parameter is String - optionsFromString is used to be turned to an options object.
If the values of this parameter is object, it is used to configure the targed actor.
The format of the object should be something like:
{ dsl-operation: function|array-of-functions-and-arguments, dsl-operation: function|array-of-functions-and-arguments, dsl-operation: function|array-of-functions-and-arguments, ... }
-
registry
ProAct.RegistryThe registry to read stored values for the DSL operations.
For example if there is 'map(f:foo)', the mapping function is read from the registry at the key 'foo'.
-
[...]
Object optionalParameters for the DSL operations.
For example if the array contains 'map($1)', the first argument passed after the actor, options and registry arguments is passed to the 'map' operation.
Returns:
The configured actor.
Properties
separator
String
final
A separator which can be used to separate multiple DSL expressions in one string.