Module: pattern

Methods

(static) decorate(fn, args, decoration) → {object}

This function will decorate a function with additional functionality, which is passed through the decoration argument.
Parameters:
Name Type Description
fn function This is a function or class that will be decorated
args array This is an array of arguments that will passed to the instantiated decorator
decoration object This is an object that contains functions that will be added to the decorator instance
Source:
Returns:
-An instance of the decorator that has been created within the decorator function
Type
object

(static) decorateCurry(fn, decoration) → {function}

This function will decorate a function with additional functionality and will return a curried function used to instantiate the decorator.
Parameters:
Name Type Description
fn function This is a function or class that will be decorated
decoration object This is an object that contains functions that will be added to the decorator instance
Source:
Returns:
- Takes constructor arguments and instantiates the decorator functuin
Type
function

(static) factory(class, …arguments) → {function}

This function returns an anonymous function. When curried returned function is executed it instantiates an instance of that function/class passed in on initial function and uses the arguments passed in initial execution or in the return anonymous function.
Parameters:
Name Type Attributes Description
class function Is a function/class that will be instantiated on the execution on returned function
arguments any <repeatable>
Are aguments that will be passed to the class during instantiation
Source:
Returns:
Type
function

(static) merge(…fns) → {function|object}

This function will merge classes and functions together and return a recursive function that will take arguments for each function until all functions/class have been initiated.
Parameters:
Name Type Attributes Description
fns function <repeatable>
This is a series of functions and classes that will be executed and their instance concatenated to one object
Source:
Returns:
- If all arguments have been satified for each function, then the combined object will be return. Otherwise another recursive function will be return that will take the arguments for the next function in queue.
Type
function | object

(static) middleware(config) → {object}

This will craete a middleware pattern that can be used as an application itself or as an extension of an application. Provide a configuration object that will setup the middleware behaviors and each behaviors associated actions
Parameters:
Name Type Description
config object This is an object that instructions the function on how to configure the middleware pattern based on behaviors and actions associated with those behaviors. Example: middleware({ behaviors: { send: { submit:function(data,cb){ fetch("/api/submit",{method: post, body: JSON.stringify(data)}) .then(cb,(err)=>throw new Error(err.message)) } } } })
Source:
Returns:
- A middleware manager is returned where one can added add middleware using the use() method. Each middleware must use next() callback as its last argument.
Type
object

(static) proxy(obj, methods) → {object}

This function will create a clone of an object and add proxy in front of that obhect. Handlers for various actions such as get, set and be passed through in the second argument
Parameters:
Name Type Description
obj object This is the object that will be cloned and referenced by the return proxy object
methods object This is an object that contains the handler for certain actions that you want to perform some logic before being passed through to the targeted object
Source:
Returns:
-Is the proxy object that you would use to access the targeted object
Type
object

(static) reveal(class, methods) → {function}

This function follows the revealing constructor pattern , used by class like Promise where we pass back a method as a callback but limit direct access to it via class instance.
Parameters:
Name Type Description
class function Is a function/class that will be extended and whose selected methods will be removed from the instance of the function/class
methods array Are methods that will be passed back as callbacks to the executor function
Source:
Returns:
- which accepts a callback that the function will execute
Type
function