Home Reference Source
import {Store} from 'simpledom-component'
public class | source

Store

A simple Store which receive all state changes with an event (string).

Constructor Summary

Public Constructor
public

constructor(initialeState: object)

The constructor.

Member Summary

Public Members
public

Don't touch :)

public

Don't touch :)

public

The state of store.

public

Don't touch :)

Method Summary

Public Methods
public

subscribe(event: string, callback: function(event: string, state: object, oldState: object), component: Component): number

Method to call to subscribe to an event.

public

Unsubcribe all subcribers.

public

Unsubscribe.

public

Unsubscribe.

public

updateState(newState: object, events: ...string)

Method to call to change the state.

Public Constructors

public constructor(initialeState: object) source

The constructor.

Params:

NameTypeAttributeDescription
initialeState object

the initial state.

Public Members

public componentsSubscribes: Array source

Don't touch :)

public componentsToUnmount: Array source

Don't touch :)

public state: object source

The state of store.

public subscribers: Object source

Don't touch :)

Public Methods

public subscribe(event: string, callback: function(event: string, state: object, oldState: object), component: Component): number source

Method to call to subscribe to an event.

There is a special event that catches all events : '*'.

Params:

NameTypeAttributeDescription
event string

event to subscribe.

callback function(event: string, state: object, oldState: object)

the callback called when receive the event.

component Component

use internally to unsubcribe component when node disappear

Return:

number

the id to put in param of unsubscribe to unsubscribe.

public unsubscribeAll() source

Unsubcribe all subcribers.

public unsubscribeByEventAndId(event: string, id: number) source

Unsubscribe.

Params:

NameTypeAttributeDescription
event string

event sent to subscribe

id number

id received at subscribe

public unsubsribe(id: number) source

Unsubscribe.

Params:

NameTypeAttributeDescription
id number

id received at subscribe

public updateState(newState: object, events: ...string) source

Method to call to change the state.

Params:

NameTypeAttributeDescription
newState object

the new state (you can put only attributes changed).

events ...string

events to the origin of the state change.