Show:

Constructs a ProAct.ArrayCore. ProAct.ArrayCore is a ProAct.Core that manages all the updates/listeners for an ProAct.Array.

It is responsible for updating length or index listeners and adding the right ones on read.

ProAct.ArrayCore is part of the proact-arrays module of ProAct.js.

Constructor

ProAct.ArrayCore

(
  • array
  • meta
)

Parameters:

  • array Object

    The shell ProAct.Array arround this core.

  • meta Object

    Optional meta data to be used to define the observer-observable behavior of the array.

Methods

accumulate

(
  • initVal
  • accumulationFunction
)
ProAct.Actor

Creates a new ProAct.Actor instance with source this and accumulation the passed accumulation function.

Should be overridden with creating the right actor.

 var actor = sourceActor.accumulate(0, function (current, el) {
   return current + el;
 });

or

 var actor = sourceActor.accumulate('+');

Parameters:

  • initVal Object

    Initial value for the accumulation. For example '0' for sum.

  • accumulationFunction Object

    The function to accumulate.

Returns:

ProAct.Actor:

A new ProAct.Actor instance with the accumulation applied.

accumulation

(
  • initVal
  • accumulationFunction
)
ProAct.Actor protected

Adds an accumulation transformation to this actor.

Accumulation is used to compute a value based on the previous one.

Parameters:

  • initVal Object

    Initial value for the accumulation. For example '0' for sum.

  • accumulationFunction Object

    The function to accumulate.

Returns:

ProAct.Actor:

this

actionFunction

(
  • fun
)
Function

Generates function wrapper around a normal function which sets the indexListener of the index calling the function.

This is used if the array is complex - contains other ProAct.js objects, and there should be special updates for their elements/properties.

Parameters:

Returns:

Function:

The action function wrapper.

addCaller

(
  • type
)
protected

Uses currentCaller to automatically add a new listener to this property if the caller is set.

This method is used by the index getters or the length getter to make every reader of the length/index a listener to it.

Parameters:

  • type String

    If the caller should be added as an 'index' listener or a 'length' listener. If skipped or null it is added as both.

afterInit

() protected

Called automatically after initialization of this actor.

By default it changes the state of this to ready.

It can be overridden to define more complex initialization logic.

beforeDestroy

() protected

Called immediately before destruction.

The idea is to be implemented by extenders to free additional resources on destroy.

call

(
  • event
)

ProAct.Core can be used as a parent listener for its managed ProAct.Actors, so it defines the call method.

By default this method calls update with this and the passed event.

Parameters:

  • event Object

    The value/event that this listener is notified for.

canClose

() protected

Checks if this can be closed.

Defaults to return true.

close

() ProAct.Actor

Closes this actor => it state becomes closed.

This sends a close event to all the subscribers to closing.

After closing the actor it can't emit events anymore.

Example:

 var actor = new ProAct.Actor();
 actor.onClose(function () {
   console.log('Done!');
 });

 actor.close(); // We will see 'Done!' on the console output.

Returns:

ProAct.Actor:

This instance - can be chained.

defaultActions

() Array protected

Inherited from ProAct.Actor but overwritten in src/js/arrays/array_core.js:237

A list of actions or action to be used when no action is passed for the methods working with actions.

For ProAct.ArrayCore these are both 'length' and 'index' actions.

Returns:

Array:

The actions to be used if no actions are provided to action related methods, like on, off, ProAct.Actor/update:method, ProAct.Actor/willUpdate:method.

defaultListeners

() Object protected

Inherited from ProAct.Actor but overwritten in src/js/arrays/array_core.js:210

Generates the initial listeners object. It is used for resetting all the listeners too.

For ProAct.ArrayCore the default listeners object is

   {
     index: [],
     length: []
   }
 

Returns:

Object:

A map containing the default listeners collections (index and length type of listeners).

defer

(
  • event
  • listener
)
ProAct.Actor protected

Defers a ProAct.Actor listener.

By default this means that the listener is put into active ProAct.Flow using it's pushOnce method, but it can be overridden.

This method determines the order of actions, triggered by the changes in the data flow. The default implementation is executing only one update on this Actor per data flow change. This means that if the Actor depends on other three Actors, and all of them get updated, it is updated only once with the last update value.

Parameters:

  • event Object

    The event/value to pass to the listener.

  • listener Object

    The listener to defer. It should be a function or object defining the call method.

Returns:

ProAct.Actor:

this

defineIndexProp

(
  • i
)
protected

Defines accessors for index of this' shell array.

For an index on every read, the currentCaller is added as an 'index' listener.

addCaller is used to retrieve the current caller and add it as the right listener.

Setting values for an index updates the 'index' listeners.

If on the index is reciding an array or an object, it is turned to reactive object/array.

Parameters:

  • i Number

    The index to define accessor for.

destroy

()

Destroys this ProAct.Actor instance.

The state of this is set to destroyed.

Calls beforeDestroy

diff

(
  • seed
  • differ
)

Creates a new ProAct.Stream with source - this. It emits the difference between the last update and the current incomming update from the source.


 source.diff(0, function(prev, v) {
     return v - prev;
 });

 // source :
 // --3---5------6---|->
 // diff:
 // --3---2------1---|->

Parameters:

  • seed Object

    A value to pass the differ function as previous on the inital notification from the source.

  • differ Function

    Creates the difference, receives two params - the previous update and the current. It can be skipped - the default differ function returns array with two elements - the previous and the curren updates.

doClose

() protected

This method is called when a close event is pushed to this Actor.

It removes all the subscriptions to the Actor and sets its state to closed.

Do not call this method; it is private!

doInit

() protected

Allocating of resources or initializing is done here.

Empty by default.

filter

(
  • filteringFunction
)
ProAct.Actor

Inherited from ProAct.Actor but overwritten in src/js/core/actor.js:939

Creates a new ProAct.Actor instance with source this and filtering the passed filtering function.

Should be overridden with creating the right actor.

 var actor = sourceActor.filter(function (el) {
   return el % 2 == 0;
 });

or

 var actor = sourceActor.filter('odd');

Parameters:

  • filteringFunction Object

    The filtering function or object with a call method, should return boolean.

Returns:

ProAct.Actor:

A new ProAct.Actor instance with the filtering applied.

filtering

(
  • filteringFunction
)
ProAct.Actor protected

Adds a filtering transformation to this actor.

Filtering can be used to filter the incoming update values. For example you can filter by only odd numbers as update values.

Parameters:

  • filteringFunction Object

    The filtering function or object with a call method, should return boolean.

Returns:

ProAct.Actor:

this

flatMap

(
  • mapper
)

Creates a new ProAct.Stream with source - this. For every update incomming from the source, a new Actor is created using the mapper function. All the updates, emitted by the streams, returned by the mapper are emitted by the Actor created by flatMap

 source.flatMap(function (v) {
   return ProAct.seq(100, [v, v +1 ]);
 });

 // source:
 // -1---2----4-----3-----2-----1---->
 // flatMap
 // -1-2-2-3--4-5---3-4---2-3---1-2-->

Parameters:

  • mapper Function

    A function that returns an ProAct.Actor using the incomming notification.

flatMapFirst

(
  • mapper
)

Creates a new ProAct.Stream with source - this. For every update comming from this, a new ProAct.Actor is created using the logic passed through mapper. The first such Actor becomes the source of the Actor, returned by this method. When it finishes, if a new Actor is emitted, it becomes the source.

 source.flatMapLast(function (v) {
   return ProAct.seq(100, [v, v + 1, v + 2, v + 3]);
 });

 // source:
 // -1---2----4-----3-----2-----1----|->
 // flatMapFirst
 // -1-2-3-4--4-5-6-7-----2-3-4-5-|->

Parameters:

  • mapper Function

    A function that returns an ProAct.Actor using the incomming notification.

flatMapLast

(
  • mapper
)

Creates a new ProAct.Stream with source - this. For every update comming from this, a new ProAct.Actor is created using the logic passed through mapper. This new Actor becomes the current source of the ProAct.Stream, returned by this method. The next update will create a new source, which will become the current one and replace the old one. This is the same as flatMapLimited, with limit of 1.

 source.flatMapLast(function (v) {
   return ProAct.seq(100, [v, v + 1, v + 2, v + 3]);
 });

 // source:
 // -1---2----4-----3-----2-----1----|->
 // flatMapLast
 // -1-2-2-3-44-5-6-3-4-5-2-3-4-1-2-3-4-|->

Parameters:

  • mapper Function

    A function that returns an ProAct.Actor using the incomming notification.

flatMapLimited

(
  • mapper
  • limit
)

Creates a new ProAct.Stream with source - this. For every update incomming from the source, a new Actor is created using the mapper function. ALl the updates, emitted by the streams, returned by the mapper are emitted by the Actor created by flatMap. The number of the currently active sources is limited by the passed limit. All the sources created after the limit is reached are queued and reused as sources later.

Parameters:

  • mapper Function

    A function that returns an ProAct.Actor using the incomming notification.

  • limit Number

    The number of the currently active sources.

fromLambda

(
  • lambda
)

Creates a new ProAct.Stream with source - this. The logic of the stream is implemented through the passed lambda parameter.

TODO The first parameter of the lambda should be called something else and not stream.

 source.fromLambda(function (stream, notification) {
   stream.trigger(notification);
 });

 // Just forwards notifications..

Parameters:

  • lambda Function

    A function, with two arguments - the returned by this function stream and notification. For every update comming from this, the lambda is called with the update and the stream in it. Has the trigger, triggerErr and triggerClose methods.

indexListener

(
  • i
)
Object protected

Generates listener for given index or reuses already generated one.

This listener mimics a property listener, the idea is - if anything is listening to index changes in this' shell (array) and the shell is complex - has elements that are ProAct.js objects, if some of this element has property change, its notification should be dispatched to all the objects, listening to index changes in the array.

So this way we can listen for stuff like array.[].foo - the foo property change for every element in the array.

Parameters:

Returns:

Object:

A listener mimicing a property one.

init

()

Initializes this actor.

This method logic is run only if the current state of this is init.

Then afterInit is called to finish the initialization.

into

(
  • [...]
)
ProAct.Actor

Links source actors into this actor. This means that this actor is listening for changes from the sources.

A good example is one stream to have another as as source -> if data comes into the source stream, it is passed to the listening too. That way the source stream is plugged into the listening one.

The listeners from makeListener, makeErrListener and makeCloseListener are used.

Chaining actors is very powerful operation. It can be used to merge many source actors into one.

 var sourceActor1 = <Actor implementation>;
 var sourceActor2 = <Actor implementation>;
 var actor = <Actor implementation>;

 actor.into(sourceActor1, sourceActor2);
 actor.on(function (v) {
   console.log(v);
 });

Now if the any of the source actors is updated, the update will be printed on the console by the actor.

Parameters:

  • [...] Object optional

    Zero or more source ProAct.Actors to set as sources.

Returns:

ProAct.Actor:

this

makeCloseListener

() Object protected

Creates the closing listener of this actor.

Every actor should have one closing listener that should pass to other actors.

This listener turns the actor in a observer for closing events.

Should be overriden with specific listener, by default it returns N.

Returns:

Object:

The closing listener of this observer.

makeErrListener

() Object protected

Creates the error listener of this actor.

Every actor should have one error listener that should pass to other actors.

This listener turns the actor in a observer for errors.

Should be overriden with specific listener, by default it returns N.

Returns:

Object:

The error listener of this observer.

makeEvent

(
  • source
  • eventData
)
ProAct.Event protected

Inherited from ProAct.Actor but overwritten in src/js/arrays/array_core.js:256

Creates the event to be send to the listeners on update.

By default this method returns ProAct.Event.Types/array:property event.

Parameters:

  • source ProAct.Event

    The source event of the event. It can be null

  • eventData Array

    An array of four elements describing the changes:

    1. ProAct.Array.Operations member defining the changing operation - for example add
    2. The index on which the chage occures.
    3. The old values beginning from the index.
    4. The new values beginning from the index.
    Can be null. If null an empty (unchanging) event is created.

Returns:

ProAct.Event:

The event.

makeListener

() Object protected

Inherited from ProAct.Actor but overwritten in src/js/core/actor.js:348

Creates the listener of this actor.

Every actor should have one listener that should pass to other actors.

This listener turns the actor in a observer.

Should be overriden with specific listener, by default it returns N.

Returns:

Object:

The listener of this observer.

map

(
  • mappingFunction
)
ProAct.Actor

Creates a new ProAct.Actor instance with source this and mapping the passed mapping function.

Should be overridden with creating the right actor.

 var actor = sourceActor.map(function (el) {
   return el * el;
 });

or

 var actor = sourceActor.map('+');

Parameters:

  • mappingFunction Object | Function | Strin

    Function or object with a call method to use as map function. Can be string for predefined mapping functions.

Returns:

ProAct.Actor:

A new ProAct.Actor instance with the mapping applied.

mapping

(
  • mappingFunction
)
ProAct.Actor protected

Adds a mapping transformation to this actor.

Mapping transformations just transform one value into another. For example if we get update with the value of 3 and we have mapping transformation that returns the updating value powered by 2, we'll get 9 as actual updating value.

Parameters:

  • mappingFunction Object

    Function or object with a call method to use as map function.

Returns:

ProAct.Actor:

this

off

(
  • actions
  • listener
)
ProAct.Actor

Removes a listener from the passed action.

If this method is called without parameters, all the listeners for all the actions are removed. The listeners are reset using defaultActions.

Examples are:

Removing a listener:

 var listener = function (v) {
   console.log(v);
 };
 actor.on(listener);
 actor.off(listener);

Or for removing all the listeners attached to an actor:

 actor.off();

Or for removing all the listeners of a given type attached to an actor:

 actor.off('error');

Or for removing a listener from different type of actions:

 var listener = function (v) {
   console.log(v);
 };
 actor.on(listener);
 actor.onErr(listener);

 actor.off(['error', 'change'], listener);

Parameters:

  • actions Array | String

    The action/actions to stop listening for. If this parameter is skipped or null/undefined, the actions from defaultActions are used.

    The actions can be skipped and on their place as first parameter to be passed the listener.

  • listener Object

    The listener to detach. If it is skipped, null or undefined all the listeners are removed from this actor.

Returns:

ProAct.Actor:

this

offAll

(
  • listener
)
ProAct.Actor

Removes all notifications listener from the passed action.

Parameters:

  • listener Object

    The listener to detach. If it is skipped, null or undefined all the listeners are removed from this actor.

Returns:

ProAct.Actor:

this

offClose

(
  • listener
)
ProAct.Actor

Removes a close notification listener from the passed action.

This is the same as calling off('close', listener) on an Actor...

Parameters:

  • listener Object

    The listener to detach. If it is skipped, null or undefined all the listeners are removed from this actor.

Returns:

ProAct.Actor:

this

offErr

(
  • listener
)
ProAct.Actor

Removes an error listener from the passed action.

This is the same as calling off('error', listener) on an Actor...

Parameters:

  • listener Object

    The listener to detach. If it is skipped, null or undefined all the listeners are removed from this actor.

Returns:

ProAct.Actor:

this

on

(
  • actions
  • listener
)
ProAct.Actor

Attaches a new listener to this ProAct.Actor.

The listener may be function or object that defines a call method.

  actor.on(function (v) {
   console.log(v);
  });

  actor.on('error', function (v) {
   console.error(v);
  });

  actor.on({
   call: function (v) {
     console.log(v);
   }
  });

Parameters:

  • actions Array | String

    The action/actions to listen for. If this parameter is skipped or null/undefined, the actions from defaultActions are used.

    The actions can be skipped and on their place as first parameter to be passed the listener.

  • listener Object

    The listener to attach. It must be instance of Function or object with a call method.

Returns:

ProAct.Actor:

this

onAll

(
  • listener
)
ProAct.Actor

Attaches the passed listener to listen to values, errors and the close notification from this ProAct.Actor.

The listener may be function or object that defines a call method.

Parameters:

  • listener Object

    The listener to attach. It must be instance of Function or object with a call method.

Returns:

ProAct.Actor:

this

onClose

(
  • listener
)
ProAct.Actor

Attaches a new close notifcation listener to this ProAct.Actor.

The listener may be function or object that defines a call method.

This is the same as calling on('close', listener) on an Actor...

Parameters:

  • listener Object

    The listener to attach. It must be instance of Function or object with a call method.

Returns:

ProAct.Actor:

this

onErr

(
  • listener
)
ProAct.Actor

Attaches a new error listener to this ProAct.Actor.

The listener may be function or object that defines a call method.

This is the same as calling on('error', listener) on an Actor...

Parameters:

  • listener Object

    The listener to attach. It must be instance of Function or object with a call method.

Returns:

ProAct.Actor:

this

out

(
  • destination
)
ProAct.Actor

The reverse of into - sets this actor as a source to the passed destination actor.

 var sourceActor = <Actor implementation>;
 var actor = <Actor implementation>;

 sourceActor.out(actor);
 actor.on(function (v) {
   console.log(v);
 });

 Now if the any of the source actors is updated, the update will be printed on the console by the actor.

Parameters:

  • destination ProAct.Actor

    The actor to set as source this to.

Returns:

ProAct.Actor:

this

prob

() ProAct.Core

Initializes this ProAct.Core. This method should be called when the core should become active.

The main idea of the method is to change the ProAct.States state of this to ready, by settuping everything needed by the shell to has observer-observable logic.

The abstract setup method is called for the actual setup. If it throws an error, this state is set to error and the core stays inactive.

Returns:

ProAct.Core:

this

reduce

(
  • initVal
  • accumulationFunction
)
ProAct.Property

Generates a new ProAct.Property containing the state of an accumulations.

The value will be updated with every update coming to this actor.

Parameters:

  • initVal Object

    Initial value for the accumulation. For example '0' for sum.

  • accumulationFunction Object

    The function to accumulate.

Returns:

ProAct.Property:

A ProAct.Property instance observing this with the accumulation applied.

setup

() protected

Inherited from ProAct.Core but overwritten in src/js/arrays/array_core.js:386

Initializes all the index accessors and the length accessor for this's shell array.

For the length on every read, the currentCaller is added as a 'length' listener.

For every index on every read, the currentCaller is added as an 'index' listener. Listener accessors are defined using defineIndexProp.

addCaller is used to retrieve the current caller and add it as the right listener.

Setting values for an index or the length updates the right listeners.

skip

(
  • n
)

Creates a new ProAct.Stream with source - this. It skips the first n updates incoming from this.

source : --3---4---5--4---3---4---5--|-> skip(3): -------------4---3---4---5--|->

Parameters:

  • n Number

    The number of notifications to skip.

skipDuplicates

(
  • comparator
)

Creates a new ProAct.Stream with source - this. It skips dublicating elements, comming one after another.


 source.skipDuplicates();

 // source :
 // --3---5---5--4---3---3---5--|->
 // skipDuplicates:
 // --3---5------4---3-------5--|->

Parameters:

  • comparator Function

    A function used to compare the elements. If nothing is passed it defaults to comparing using ===.

skipWhile

(
  • condition
)

Creates a new ProAct.Stream with source - this. It skips notifications from its source, while a condition is true.


 source.skipWhile(function (v) {
     return v % 2 === 1;
 });

 // source :
 // --3---5---2--4---3---4---5--|->
 // skipWhile:
 // ----------2--4---3---4---5--|->

Parameters:

  • condition Function

    A condition function, which is called for each of the incoming values While it returns true, the elements are skipped, after it returns false for the first time, the current and all the following values are emitted.

take

(
  • limit
)

Creates a new ProAct.Stream with source - this. It takes the first limit updates incoming from this.

source : --3---4---5--4---3---4---5--|-> skip(3): --3---4---5--|->

Parameters:

  • limit Number

    The number of notifications to emit.

takeWhile

(
  • condition
)

Creates a new ProAct.Stream with source - this. It emits notifications from its source, while a condition is true.


 source.takeWhile(function (v) {
     return v % 2 === 1;
 });

 // source :
 // --3---5---2--4---3---4---5--|->
 // takeWhile:
 // --3---5--|->

Parameters:

  • condition Function

    A condition function, which is called for each of the incoming values While it returns true, the elements are emitted, after it returns false for the first time, the stream created by takeWhile closes.

toProArray

() ProAct.Array

Creates and returns a ProAct.Array instance, which tracks the changes of this. Uses the current queue for queueing changes.

Returns:

ProAct.Array:

A ProAct.Array instance tracking the changes of this.

toProperty

()

Creates a {{{#crossLink "ProAct.Property"}}{{/crossLink}} instance, dependent on this. Comes from the proact-properties module.

toStream

()

Turns this ProAct.Actor to a ProAct.Stream.

In reality this method creates a new Stream with source this.

transform

(
  • transformation
)
ProAct.Actor protected

Adds a new transformation to the list of transformations of this actor.

A transformation is a function or an object that has a call method defined. This function or call method should have one argument and to return a transformed version of it. If the returned value is {@link ProAct.Actor.BadValue}, the next transformations are skipped and the updating value/event becomes - bad value.

Every value/event that updates this actor will be transformed using the new transformation.

Parameters:

  • transformation Object

    The transformation to add.

Returns:

ProAct.Actor:

this

transformStored

(
  • transformation
  • type
)
ProAct.Actor protected

Inherited from ProAct.Actor but overwritten in src/js/core/actor.js:796

Adds a new transformation to the list of transformations of this actor.

A transformation is a function or an object that has a call method defined. This function or call method should have one argument and to return a transformed version of it. If the returned value is {@link ProAct.Actor.BadValue}, the next transformations are skipped and the updating value/event becomes - bad value.

Every value/event that updates this actor will be transformed using the new transformation.

The idea of this method is that it just calls transform, but it can be overidden from another module.

TODO Maybe transformStored is a bad name

Parameters:

  • transformation Object

    The transformation to add. Can be string - to be retrieved by name.

  • type String

    The type of the transformation, for example mapping.

Returns:

ProAct.Actor:

this

updateByDiff

(
  • array
)
ProAct.ArrayCore

Special update method for updating listeners by comparrison to another array.

For every difference between this shell's array and the passed one, there will be listeners notification.

Parameters:

  • array Array

    The array to compare to.

Returns:

updateSplice

(
  • index
  • spliced
  • newItems
)
ProAct.ArrayCore

Special update method for updating listeners after a splice call.

Depending on the changes the index listeners, the length listeners or both can be notified.

Parameters:

  • index Number

    The index of the splice operation.

  • spliced Array

    A list of the deleted items. Can be empty.

  • newItems Array

    A list of the newly added items. Can be empty.

Returns:

value

() Object

A function to be set to the shell object's p field (if it is configured in ProAct.Configuration.

This function is the link to the this ProAct.Core of the shell. It can be overridden to return different aspects of the core depending on parameters passed.

Returns:

Object:

Some aspects of this ProAct.Core.

Properties

constructor

ProAct.ArrayCore final

Inherited from ProAct.Actor but overwritten in src/js/arrays/array_core.js:38

Reference to the constructor of this object.