Fork me on GitHub
Show:

ClassFactory

Summary

A Factory for creating Class constructors.

Allows for "soft" binding arguments to the Class constructor; bound arguments will serve as the default constructor arguments, but any arguments passed in on instantiation will override the bound arguments.

For example: var Klass = new ClassFactory(ParentKlass, ['a', 'b', 'c']); new Klass('x'); // ParentKlass ctor called with ('x', 'b', 'c')

This can be useful for wiring up Classes which are simply configured versions of a parent class. For example,

var DefaultSelectedModel = new ClassFactory(aeris.Model, selected: true); var model = new DefaultSelectedModel();

model.get('selected') // true

// Argument binding is "soft" var notSelectedModel = new DefaultSelectedModel(selected: false); notSelectedModel.get('selected') // false

Use the extendArgObjects option to extend instance argument objects.

For example:

var SomeModelClass = new ClassFactory(Model, [foo: 'bar', hello: 'World'], extendArgObjects: ...];

var model = new SomeModelClass(hello: 'Universe');

// with extendArgObjects: true // called attrs extend the bound attrs model.toJSON() === foo: 'bar', hello: 'Universe');

// with extendArgObjects: false // called attrs replace the bound attrs model.toJSON === hello: 'Universe'

Constructor

aeris.ClassFactory

Syntax

aeris.ClassFactory

(
  • opt_Type
  • opt_boundArgs
  • opt_options
  • extendArgObjects
)
Function

Summary

Parameters:

  • opt_Type Function=

    Parent class constructor.

  • opt_boundArgs Array.<*>

    Arguments to bind to the class constructor.

  • opt_options Object=
  • extendArgObjects Boolean=

    Defaults to false. See {aeris.ClassFactory} documentation for details.

Returns:

Function:

Class constructor.

Item Index

Methods

parseObjectValues

Syntax

parseObjectValues

(
  • str
)
*

Summary

Parse end-leaf values of deep nested objects, replacing string'ed objects to their primitive values.

Useful for processing inputs that are serialized only as strings (eg. forms, querystring routes).

eg. { num: '18.5', arr: [ 'true', { obj: { boolFalse: 'false', nums: ['16.5', 82, '19.001'] } } ], obj: { str: 'str', boolTrue: 'true', boolTrueReal: true, nums: { numsA: [22, '15'], numsB: [18, { num: '-96.15' }] } } } becomes: { num: 18.5, arr: [ true, { obj: { boolFalse: false, nums: [16.5, 82, 19.001] } } ], obj: { str: 'str', boolTrue: true, boolTrueReal: true, nums: { numsA: [22, 15], numsB: [18, { num: -96.15 }] } } }

Parameters:

Returns:

*: