Home Manual Reference Source Test Repository

Function

Static Public Summary
public

Clears all saved containers.

public

Compose a container from containers or DOM elements.

public

createContainer(domElement: Element, initialState: Object, reducers: ...Function): Container

Create a new Container instance with optional initial state and n reducers.

public

Generates a unique hex ID for Container instances.

public

fetchContainer(arg: String | Element | Object): class Container

Fetch a saved container by container ID, DOM element, or by a container instance.

public

Execute a function for each container.

public

getAllContainers(): MapIterator<String, Container>

Returns an interator for all containers.

public

Returns immutable private stardux data for a given input.

public

Creates a or returns a new Container instance from a given DOM element.

public

realignContainerTree(container: Container, recursive: Boolean, forceOrphanRestoration: Boolean)

Realign container DOM tree by removing containers not found in container DOM tree.

public

Removes a container from the internal tree.

public

replaceDOMElement(container: Container, domElement: Element): Container

Replace container element with another.

public

restoreContainerFromJSON(json: Object, initialState: Object, reducers: ...Function): Container

Create or restore a Container instance from a JSON object with an optional state object a reducers.

public

restoreOrphanedTree(container: Container | Element, recursive: Boolean)

Restores orphaned children containers still attached to a container.

public

Save a container to the known containers map.

public

traverseContainer(container: Container, fn: Function, scope: Object)

Traverse a container's tree recursively.

Static Public

public clearContainers(): undefined source

import {clearContainers} from 'stardux/src/index.js'

Clears all saved containers. This will call removeContainer for every saved container.

Return:

undefined

public composeContainers(root: Element | Container, containers: ...Element | Container | String): Container source

import {composeContainers} from 'stardux/src/index.js'

Compose a container from containers or DOM elements. If a Container or Element is given as first argument then it is treated as the root and all subsequent arguments are treated as direct descendants of the root. If the second argument is an array or an "array like" object then it is treated as direct descendants of the root and all subsequent arguments are ignored. If an array or "array like" object is passed as the first argument a new root container is created and the first argument is treated as direct descendants of the newly created root container. The root container, newly created or restored is returned.

Params:

NameTypeAttributeDescription
root Element | Container
  • nullable: true
containers ...Element | Container | String
  • nullable: true

Return:

Container

Example:

Compose containers together with new root.
  const a = createContainer()
  const b = createContainer()
  const composed = composeContainers([a, b])
Compose containers together with given root.
  const a = createContainer()
  const b = createContainer()
  const c = createContainer()
  const composed = composeContainers(a, [b, c])

public createContainer(domElement: Element, initialState: Object, reducers: ...Function): Container source

import {createContainer} from 'stardux/src/index.js'

Create a new Container instance with optional initial state and n reducers.

Params:

NameTypeAttributeDescription
domElement Element
initialState Object
  • optional
  • nullable: true

Initial state object

reducers ...Function
  • optional

Return:

Container

Example:

Create an anonymouse container.
  const container = createContainer()
Create a container for a DOM Element.
  const container = createContainer(domElement)
Create a container for a DOM Element with initial state.
  const container = createContainer(domElement, {value: 0})
Create a container for a DOM Element with initial state and reducers.
  const container = createContainer(domElement, {value: 0}, (state = {}, action) => {
    if (UPATE == action.type) {
       return {
         value: state.action + action.data.value
       }
    }
  })

public createContainerUid(): String source

import {createContainerUid} from 'stardux/src/index.js'

Generates a unique hex ID for Container instances.

Return:

String

Example:

Create a unique container ID
  const id = createContainerUid()

public fetchContainer(arg: String | Element | Object): class Container source

import {fetchContainer} from 'stardux/src/index.js'

Fetch a saved container by container ID, DOM element, or by a container instance.

Params:

NameTypeAttributeDescription
arg String | Element | Object
arg.id String
  • optional

Container ID

Return:

class Container

Example:

Fetch container by id.
  const container = fetchContainer(id)
Fetch container by DOM element.
  const container = fetchContainer(domElement)
Fetch container by object with id.
  const container = fetchContainer({id: id})

public forEachContainer(fn: Function, scope: Object) source

import {forEachContainer} from 'stardux/src/index.js'

Execute a function for each container.

Params:

NameTypeAttributeDescription
fn Function
scope Object
  • optional

Example:

  forEachContainer(container => {
    console.log(container)
  })

public getAllContainers(): MapIterator<String, Container> source

import {getAllContainers} from 'stardux/src/index.js'

Returns an interator for all containers.

Return:

MapIterator<String, Container>

Example:

Get an iterator for all containers.
  const it = getAllContainers()
  for (let pair of [ ...it ])
    console.log(pair)

public getContainerData(arg: Container | Element | String): Object source

import {getContainerData} from 'stardux/src/index.js'

Returns immutable private stardux data for a given input. Input can be a container, an Element, or a string representing a container ID. If data is not found then null is returned.

Params:

NameTypeAttributeDescription
arg Container | Element | String

Return:

Object

Example:

Get container data for a container.
  const data = getContainerData(container)
Get container data for a container from a given DOM element.
  const data = getContainerData(container)
Get container data for a container from a given id.
  const data = getContainerData(id)

public makeContainer(domElement: Element): Container source

import {makeContainer} from 'stardux/src/index.js'

Creates a or returns a new Container instance from a given DOM element.

If a DOM element is already associated with a container then the container is just returned, otherwise a new one is created.

Params:

NameTypeAttributeDescription
domElement Element

Return:

Container

Example:

Make a container for a DOM Element.
  const container = makeContainer(document.body)

public realignContainerTree(container: Container, recursive: Boolean, forceOrphanRestoration: Boolean) source

import {realignContainerTree} from 'stardux/src/index.js'

Realign container DOM tree by removing containers not found in container DOM tree. If recursive is set to true then realignment is applied to all subsequent child containers. If forceOrphanRestoration is set to true then orphan containers are restored.

Params:

NameTypeAttributeDescription
container Container
recursive Boolean
  • optional
forceOrphanRestoration Boolean
  • optional

public removeContainer(arg: String | Container | Element, recursive: Boolean): Boolean source

import {removeContainer} from 'stardux/src/index.js'

Removes a container from the internal tree. The container is also removed from its parent if it is attched to one. A string ID, DOM element, or Container may be used as an argument.

Params:

NameTypeAttributeDescription
arg String | Container | Element
recursive Boolean
  • optional

Return:

Boolean

Example:

Remove container by id.
  removeContainer(id)
Remove container by DOM element.
  removeContainer(domElement)
Remove container by object with id.
  removeContainer({id: id})

public replaceDOMElement(container: Container, domElement: Element): Container source

import {replaceDOMElement} from 'stardux/src/index.js'

Replace container element with another. This will remove all children containers and realign the container tree.

Params:

NameTypeAttributeDescription
container Container
domElement Element

Return:

Container

public restoreContainerFromJSON(json: Object, initialState: Object, reducers: ...Function): Container source

import {restoreContainerFromJSON} from 'stardux/src/index.js'

Create or restore a Container instance from a JSON object with an optional state object a reducers.

Containers are created if they do not already exist internally.

Params:

NameTypeAttributeDescription
json Object
initialState Object
  • optional
  • nullable: true

Initial state object

reducers ...Function
  • optional

Return:

Container

Example:

Restore or create a container from JSON.
  const container = restoreContainerFromJSON(json)
Restore or create a container from JSON with initial state.
  const container = restoreContainerFromJSON(json, {value: 0})
Restore or create a container from JSON with initial state and reducers.
  const container = restoreContainerFromJSON(json, {value: 0}, ...reducers)

public restoreOrphanedTree(container: Container | Element, recursive: Boolean) source

import {restoreOrphanedTree} from 'stardux/src/index.js'

Restores orphaned children containers still attached to a container. An orphan container is a container who belongs to a set of containers and it's DOM element is not attched to a DOM tree (The parent container's DOM element).

Params:

NameTypeAttributeDescription
container Container | Element
recursive Boolean
  • optional

public saveContainer(container: Container | Element): Boolean source

import {saveContainer} from 'stardux/src/index.js'

Save a container to the known containers map. A DOM element may be passed if it has been claimed by a Container instance.

Params:

NameTypeAttributeDescription
container Container | Element

Return:

Boolean

Example:

Save a container
  saveContainer(container)
Save a container by DOM element
  saveContainer(domElement)

public traverseContainer(container: Container, fn: Function, scope: Object) source

import {traverseContainer} from 'stardux/src/index.js'

Traverse a container's tree recursively.

Params:

NameTypeAttributeDescription
container Container
fn Function
scope Object
  • optional

Example:

  traverseContainer(container, child => {
    console.log(child)
  })