new Context(options)
conbo.Context
This is your application's event bus and dependency injector, and is
usually where all your models and web service classes are registered,
using mapSingleton(...), and Command classes are mapped to events
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | Object containing initialisation options, including 'app' (Application) and 'namespace' (Namespace) |
Extends
Members
app
The Application instance associated with this context
namespace
The Namespace this context exists in
parentContext
If this is a subcontext, this is a reference to the Context that created it
supro
Similar to `super` in ActionScript or Java, this property enables
you to access properties and methods of the super class prototype,
which is the case of JavaScript is the next prototype up the chain
- Inherited From:
- Source:
Methods
__construct(options)
Constructor: DO NOT override! (Use initialize instead)
Parameters:
Name | Type | Description |
---|---|---|
options |
addEventListener(type, handler, scopeopt, priorityopt, onceopt) → {conbo.EventDispatcher}
Add a listener for a particular event type
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
string | Type of event ('change') or events ('change blur') | ||
handler |
function | Function that should be called | ||
scope |
Object |
<optional> |
Options object (recommended) or the scope in which to run the event handler (deprecated) | |
priority |
number |
<optional> |
0 | The event handler's priority when the event is dispatached (deprecated) |
once |
boolean |
<optional> |
false | Should the event listener automatically be removed after it has been called once? (deprecated) |
- Inherited From:
- Source:
Returns:
A reference to this class instance
addTo()
Add this Context to the specified Object, or create an object with a
reference to this Context
bindAll(…methodNameopt) → {this}
Scope all methods of this class instance to this class instance
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
methodName |
string |
<optional> <repeatable> |
Specific method names to bind (all will be bound if none specified) |
- Inherited From:
- Source:
Returns:
- Type
- this
createSubcontext(contextClassopt, cloneSingletonsopt, cloneCommandsopt) → {conbo.Context}
Create a new subcontext that shares the same application
and namespace as this one
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
contextClass |
class |
<optional> |
The context class to use (default: conbo.Context) |
cloneSingletons |
boolean |
<optional> |
Should this Context's singletons be duplicated on the new subcontext? (default: false) |
cloneCommands |
boolean |
<optional> |
Should this Context's commands be duplicated on the new subcontext? (default: false) |
Returns:
- Type
- conbo.Context
declarations() → {void}
Declarations is used to declare instance properties used by this class
Parameters:
Type | Attributes | Description |
---|---|---|
* |
<repeatable> |
- Inherited From:
- Source:
Returns:
- Type
- void
destroy()
Clears all commands and singletons, and removes all listeners
- Overrides:
- Source:
dispatchChange(propName) → {conbo.EventDispatcher}
Dispatch a change event for one or more changed properties
Parameters:
Name | Type | Description |
---|---|---|
propName |
string | The name of the property that has changed |
- Inherited From:
- Source:
Returns:
A reference to this class instance
dispatchEvent(event) → {conbo.EventDispatcher}
Dispatch the event to listeners
Parameters:
Name | Type | Description |
---|---|---|
event |
conbo.Event | The event to dispatch |
- Inherited From:
- Source:
Returns:
A reference to this class instance
hasEventListener(type, handleropt, scopeopt) → {boolean}
Does this object have an event listener of the specified type?
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
string | Type of event (e.g. 'change') | |
handler |
function |
<optional> |
Function that should be called |
scope |
Object |
<optional> |
Options object (recommended) or the scope in which to run the event handler (deprecated) |
- Inherited From:
- Source:
Returns:
True if this object has the specified event listener, false if it does not
- Type
- boolean
initialize() → {void}
Initialize (entry point) is called immediately after the constructor has completed
Parameters:
Type | Attributes | Description |
---|---|---|
* |
<repeatable> |
- Inherited From:
- Source:
Returns:
- Type
- void
inject(obj, …names)
Inject constants and singleton instances into specified object
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
* | The object to inject singletons into | |
names |
string |
<repeatable> |
Names of properties to inject (optional) |
injectSingletons(obj)
Inject constants and singleton instances into specified object
Parameters:
Name | Type | Description |
---|---|---|
obj |
* | The object to inject singletons into |
mapCommand(eventType, commandClass)
Map specified Command class the given event
Parameters:
Name | Type | Description |
---|---|---|
eventType |
string | The name of the event |
commandClass |
class | The command class to instantiate when the event is dispatched |
mapConstant()
Map constant value to a property name
To inject a constant into a class, register the property name
with the Context and declare the property as undefined in your
class to enable it to be injected at run time
Examples
context.mapConstant('MY_VALUE', 123);
MY_VALUE: undefined
mapSingleton()
Map class instance to a property name
To inject a property into a class, register the property name
with the Context and declare the value as undefined in your class
to enable it to be injected at run time
Examples
context.mapSingleton('myProperty', MyModel);
myProperty: undefined
preinitialize() → {void}
Preinitialize is called before any code in the constructor has been run
Parameters:
Type | Attributes | Description |
---|---|---|
* |
<repeatable> |
- Inherited From:
- Source:
Returns:
- Type
- void
removeEventListener(typeopt, handleropt, scopeopt) → {conbo.EventDispatcher}
Remove a listener for a particular event type
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
string |
<optional> |
Type of event ('change') or events ('change blur'), if not specified, all listeners will be removed |
handler |
function |
<optional> |
Function that should be called, if not specified, all listeners of the specified type will be removed |
scope |
Object |
<optional> |
Options object (recommended) or the scope in which to run the event handler (deprecated) |
- Inherited From:
- Source:
Returns:
A reference to this class instance
toString() → {string}
String representation of the current class
- Overrides:
- Source:
Returns:
- Type
- string
uninject(obj)
Set constants and singleton instances on the specified object to undefined
Parameters:
Name | Type | Description |
---|---|---|
obj |
* | The object to remove singletons from |
uninjectSingletons(obj)
Set constants and singleton instances on the specified object to undefined
Parameters:
Name | Type | Description |
---|---|---|
obj |
* | The object to remove singletons from |
unmapCommand()
Unmap specified Command class from given event
unmapConstant()
Unmap constant value from a property name
unmapSingleton()
Unmap class instance from a property name