Leverege Platform

Leverege Platform

  • Overview
  • JSDocs
  • REST API
  • Help

›JSDoc

JSDoc

  • Home
  • API Server
  • API Attributes
  • Api Patch Ops
  • API Redux
  • Array Util
  • Base62 Util
  • Cache
  • Cluster Manager
  • Data Store
  • Exit
  • Factory
  • Limit
  • Lock
  • Message Queue
  • Messages
  • Path
  • Permissions
  • Reasoner
  • String Util
  • UI Active Theme
  • UI Elements
  • UI Linear View Elements
  • UI Mapbox Elements
  • Validator

Factory

Classes

Factory

The Factory allows the lookup and construction of objects/results based on a type. A sample usage is:

const f = new Factory( ) f.add( 'myType', MyTypeMsg ) f.add( 'myOtherType', MyOtherTypeMsg ) const msg = f.create( { type : 'myOtherType', value : 5 } ) // msg is equivalent to new MyOtherMsg( { type : 'myOtherType', value : 5 } )

Strategies when create( obj, arg1, argN ) is called. Below, clzz equals get( obj ) ALL (default): new clzz( obj, arg1, argN ) // clzz is a class clzz( obj, arg1, argN ) // clzz is a function NONE: new clzz( ) clzz( ) ARGS: new clzz( arg1, argN ) clzz( arg1, argN ) MERGE: const alt1 = { model : obj, ...arg1 } new clzz( alt1, argN ) clzz( alt1, argN ) LOOKUP: clzz : return strategy( this, clzz, obj, arg1, argN )

ALL is equivalent to ARGS is create( model, model, arg1, argN ) is called

Functions

allStrategy(factory, clzz, typeOrObject) ⇒

A strategy where the args passed into the constructor/function are ( typeOrObject, arg1, arg2, ...etc... )

noneStrategy(factory, clzz, typeOrObject) ⇒

A strategy where no args passed into the constructor/function

argsStrategy(factory, clzz, typeOrObject) ⇒

A strategy where the args passed into the constructor/function are ( arg1, arg2, ...etc... )

lookupStrategy(factory, clzz, typeOrObject) ⇒

A strategy where clzz is returned

mergeStrategy(key) ⇒

Creates a strategy where the args passed into the constructor/function are ( MOD, arg2, ...etc... ), where MOD is { [key] : typeOrObject, ...args[0] }

reactStrategy(React, propKey) ⇒

Creates a strategy for createing react elements. The clzz object given to the strategy is assumed to be a React.Component or React pure component/function. the typeOrObejct will be merge into the props at the specified propKey.

Factory

The Factory allows the lookup and construction of objects/results based on a type. A sample usage is:

const f = new Factory( ) f.add( 'myType', MyTypeMsg ) f.add( 'myOtherType', MyOtherTypeMsg ) const msg = f.create( { type : 'myOtherType', value : 5 } ) // msg is equivalent to new MyOtherMsg( { type : 'myOtherType', value : 5 } )

Strategies when create( obj, arg1, argN ) is called. Below, clzz equals get( obj ) ALL (default): new clzz( obj, arg1, argN ) // clzz is a class clzz( obj, arg1, argN ) // clzz is a function NONE: new clzz( ) clzz( ) ARGS: new clzz( arg1, argN ) clzz( arg1, argN ) MERGE: const alt1 = { model : obj, ...arg1 } new clzz( alt1, argN ) clzz( alt1, argN ) LOOKUP: clzz : return strategy( this, clzz, obj, arg1, argN )

ALL is equivalent to ARGS is create( model, model, arg1, argN ) is called

Kind: global class

  • Factory
    • new Factory(options, name, typeKey, [registry], defaultObject, strategy)
    • .add(type, obj)
    • .remove(type)
    • .getType(typeOrObj) ⇒
    • .has() ⇒ boolean
    • .get(type) ⇒ any
    • .getAll() ⇒ object
    • .create(...args) ⇒ any

new Factory(options, name, typeKey, [registry], defaultObject, strategy)

Create a factory object.

ParamTypeDescription
optionsobject \functionthe options for the factory. If this is a function, it is the strategy.
namestringthe name of the factory
typeKeystringthe property to look at when determining the type of an object. Defaults to 'type'
[registry]objecta type to obj map. Using this is the same as calling add for each key/value pair
defaultObjectanyIf a lookup results in null/undefined, this object will be used
strategyfunctiona function( factory, clzz, typeOrClass, ...args ) invoked to create the returned object. (Defaults to Factory.ALL)

factory.add(type, obj)

Registers an object to support the type. If there is already an object registered for the type, this will throw an exception unless overwrite is set to true

Kind: instance method of Factory

ParamTypeDescription
typestringthe type to register
objanythe thing to register for the type

factory.remove(type)

Removes a registered type.

Kind: instance method of Factory

ParamTypeDescription
typestringthe type to remove

factory.getType(typeOrObj) ⇒

If typeOrObj is an object, this will extract the type from the object usin the typeKey field. Otherwise, typeOrObject will be returned

Kind: instance method of Factory
Returns: the type

ParamTypeDescription
typeOrObjanythe type or an object containing the type

factory.has() ⇒ boolean

Return true if an object is registered to suppor the type.

Kind: instance method of Factory
Returns: boolean - true if there is a registered object

factory.get(type) ⇒ any

Returns the function/class registered to manager the object of the specified type.

Kind: instance method of Factory
Returns: any - the thing registered at that that location

ParamTypeDescription
typeobject \stringIf this is a string, it is used as the type to lookup. If it is an object, the typeKey field of the object is used to do the lookup.

factory.getAll() ⇒ object

Returns an object containing the mapping between the types and the things registered to suppor that type.

Kind: instance method of Factory
Returns: object - the mapping

factory.create(...args) ⇒ any

Creates the thing used to support the typeOfObj.

Kind: instance method of Factory
Returns: any - the constructed item
Oaram: object|string typeOrObj usually the object we're creating a handler for, but in some strategies, this might just be the type

ParamTypeDescription
...argsarraythe rest of the params

allStrategy(factory, clzz, typeOrObject) ⇒

A strategy where the args passed into the constructor/function are ( typeOrObject, arg1, arg2, ...etc... )

Kind: global function
Returns: the new class, the result of the function, or clzz if clzz is not a class or function.

ParamTypeDescription
factoryFactorythe invoking factory
clzzClass \functionthe registered
typeOrObjectobject \stringthe object used to lookup the clzz
...argsarraythe rest of the args

noneStrategy(factory, clzz, typeOrObject) ⇒

A strategy where no args passed into the constructor/function

Kind: global function
Returns: the new class, the result of the function, or clzz if clzz is not a class or function.

ParamTypeDescription
factoryFactorythe invoking factory
clzzClass \functionthe registered
typeOrObjectobject \stringthe object used to lookup the clzz
...argsarraythe rest of the args

argsStrategy(factory, clzz, typeOrObject) ⇒

A strategy where the args passed into the constructor/function are ( arg1, arg2, ...etc... )

Kind: global function
Returns: the new class, the result of the function, or clzz if clzz is not a class or function.

ParamTypeDescription
factoryFactorythe invoking factory
clzzClass \functionthe registered
typeOrObjectobject \stringthe object used to lookup the clzz
...argsarraythe rest of the args

lookupStrategy(factory, clzz, typeOrObject) ⇒

A strategy where clzz is returned

Kind: global function
Returns: the new class, the result of the function, or clzz if clzz is not a class or function.

ParamTypeDescription
factoryFactorythe invoking factory
clzzClass \functionthe registered
typeOrObjectobject \stringthe object used to lookup the clzz
...argsarraythe rest of the args

mergeStrategy(key) ⇒

Creates a strategy where the args passed into the constructor/function are ( MOD, arg2, ...etc... ), where MOD is { [key] : typeOrObject, ...args[0] }

Kind: global function
Returns: the new merge strategy

ParamTypeDefaultDescription
keystring"model"the the merge key

reactStrategy(React, propKey) ⇒

Creates a strategy for createing react elements. The clzz object given to the strategy is assumed to be a React.Component or React pure component/function. the typeOrObejct will be merge into the props at the specified propKey.

Kind: global function
Returns: the react element

ParamTypeDefaultDescription
ReactReactthe React library
propKeystring \false"model"if this is a string, the typeOrObject will be merged into the props at that key. Otherwise, it will not be supplied
← ExitLimit →
  • Classes
  • Functions
  • Factory
    • new Factory(options, name, typeKey, [registry], defaultObject, strategy)
    • factory.add(type, obj)
    • factory.remove(type)
    • factory.getType(typeOrObj) ⇒
    • factory.has() ⇒ boolean
    • factory.get(type) ⇒ any
    • factory.getAll() ⇒ object
    • factory.create(...args) ⇒ any
  • allStrategy(factory, clzz, typeOrObject) ⇒
  • noneStrategy(factory, clzz, typeOrObject) ⇒
  • argsStrategy(factory, clzz, typeOrObject) ⇒
  • lookupStrategy(factory, clzz, typeOrObject) ⇒
  • mergeStrategy(key) ⇒
  • reactStrategy(React, propKey) ⇒
Leverege Platform
Docs
Overview
Connect
FacebookLinkedInTwitter
Facebook Open Source