Relation
Constructor
new Relation(klass)
Instance Properties
Object containing references to objects this instance is listening to
Object containing all event listeners
Unique identifier for this event bus instance
Instance Methods
Bind an event to a callback function. Passing "*" will bind
the callback to all events fired.
If the options.once is true, the event will only be triggered a single time. After the first time the callback is invoked, its listener will be removed. If multiple events are passed in as an array, the handler will fire once for each event, not once for a combination of all events.
Parameters
name
:
string
|
Array.<string>
|
object
Event name(s) or object of event/callback pairs
callback
:
function
|
object
Callback function or options object if name is an object
options
:
object
optionalEvent options
once
:
boolean
optionalWhether the event should only trigger once
context
:
object
optionalThe context to bind the event to
listener
:
object
optionalThe listener object
Returns
EventBus
Returns this for chaining
Tell this object to listen to an event in another object, while keeping track of what it's listening to for easier unbinding later.
Parameters
obj
:
object
|
NodeList
The object to listen to events on
name
:
string
|
Array.<string>
|
object
Event name(s) or object of event/callback pairs
callback
:
function
|
object
Callback function or options object if name is an object
options
:
object
optionalEvent options
once
:
boolean
optionalWhether the event should only trigger once
context
:
object
optionalThe context to bind the event to
Returns
EventBus
Returns this for chaining
Trigger one or many events, firing all bound callbacks. Callbacks are
passed the same arguments as dispatchEvent is, apart from the event name
(unless you're listening on "*", which will cause your callback to
receive the true name of the event as the first argument).
Parameters
name
:
string
|
Array.<string>
Event name or array of event names
args
:
*
Arguments to pass to the event handlers
Returns
EventBus
Returns this for chaining
Group the results by a attribute
Parameters
on
:
*
Attributes to group the results by
Returns
placeholder function for extending
Load and return the relation.
If the relation is loaded the loaded relation will be returned and no events will be fired.
Use [reload]{@linkcode Relation#reload} if you wish to fetch the relation from the server again.
If there is currently a request in flight to fetch the relation from the server the result of that request will be returned after the original load finishes. A new request will not be sent.
Parameters
eventParameters
:
*
Parameters to pass to events fired in this function
Returns
Promise.Record>>
Load the relation from the server even if it's in memory.
If there is currently a request in flight to fetch the relation it will be cancelled and a new request will be sent. The result of the new request will be used to fullfill the promise of the original request before fulling the promise of the new request.
Parameters
eventParameters
:
*
Parameters to pass to events fired in this function
Returns
Array.<Record>
Remove one or many callbacks that match the arguments. If called with no arguments, removes all callbacks for all events.
Parameters
name
:
string
|
Array.<string>
|
object
|
null
optionalEvent name(s) or object of event/callback pairs
callback
:
function
|
object
|
null
optionalCallback function or options object if name is an object
options
:
object
optionalEvent options
once
:
boolean
optionalMatch only events set to trigger once
context
:
object
optionalMatch only events bound to this context
listener
:
object
optionalMatch only events bound by this listener
Returns
EventBus
Returns this for chaining
Tell this object to stop listening to either specific events or to every object it's currently listening to.
Parameters
obj
:
object
|
NodeList
optionalThe object to stop listening to; if omitted, stops listening to all objects
name
:
string
|
Array.<string>
|
object
optionalEvent name(s) or object of event/callback pairs
callback
:
function
optionalCallback function to remove
options
:
object
optionalEvent options
once
:
boolean
optionalMatch only events set to trigger once
context
:
object
optionalMatch only events bound to this context
Returns
EventBus
Returns this for chaining
Sets the records of this relation, removing and adding records as necessary.
Parameters
records
:
Array.<Record>
eventParameters
:
*
Parameters to pass to events fired in this function
Returns
Events
afterAdd
Fired when records are added to the relation. Will not be called for any records already in memory.
Parameters
eventParameters
:
*
optional parameters from the {@link Relation#setTarget} call that gets passed to the callbacks.
Fired after the request to the server has been returned and processed and the models are loaded.
Parameters
eventParameters
:
*
optional parameters from the {@link Relation#load} call that get passed to the callbacks.
Fired when records are removed to the relation.
Parameters
eventParameters
:
*
optional parameters from the {@link Relation#setTarget} call that gets passed to the callbacks.
Fired before sending the request to the server to load the records.
Parameters
eventParameters
:
*
optional parameters from the {@link Relation#load} call that get passed to the callbacks.
Fired before setting (adding or removing) the records of the relation.
Parameters
eventParameters
:
*
optional parameters from the {@link Relation#setTarget} call that gets passed to the callbacks.
changed
An attribute of the relation was changed
Parameters
attribute
:
"distinct"
|
"limit"
|
"offset"
|
"order"
|
"where"
The attribute on the query/relation that changed
newValue
:
*
The new value of the attribute
attribute of the relation was changed; where attribute is any of the following
"distinct", "limit", "offset", "order", "where"
Parameters
newValue
:
*
The new value of the attribute
