Class: Resourced

data/backbone. Resourced

new module:data/backbone.Resourced()

modules/data/backbone.js, line 33

Extends the BaseWidget class to use Backbone's Collection and Models as resources.



inherited private_activate(context){*}

widgets/Base.js, line 757

Completes the waking sequence by activating and showing the instance. This is a the fulfilled handler of wake().


  • post_wake: triggered at the end of a successful wake, takes wake()'s context param as argument.
Name Type Description
context * optional

the context argument passed to BaseWidget#wake.

result of calling appear(), which could be a Promise.

inherited private_center(){Widget}

widgets/Base.js, line 877

Centers the widget, vertically and horizontally.

inherited private_deactivate(context, reason){*}

widgets/Base.js, line 796

Completes the waking sequence of a broken waking sequence. This is a the rejected handler of wake().

If wake_failed returns a truthy result it's passed to another call to wake(), and another attempt will be made. If not, sleep() is called and the reason is returned in a subsequent rejected Promise, and the widgets branch will continue to fold back.


  • wake_failed: triggered at the beginning, takes all arguments of the rejected BaseWidget#wakeContained, or render() call.
Name Type Description
context *

the context argument passed to BaseWidget#wake.

reason *

the rejection reason.

result of another call to wake() or a rejected Promise.

inherited private_finally(){Widget}

widgets/Base.js, line 931

Cleans up all lifecycle related operations.

A utility method that's called at the end of every lifecycle method call. If you wish to forcibly allow signals, that are triggered once per lifecycle stage - e.g. pre_render, to be triggerable again call this method.

inherited private_generateId(){string}

widgets/Base.js, line 818

Generates an id for the instance.

generated id.

inherited private_parseHandler(handler){function}

uijet.js, line 780

Normalizes a handler into a function if it's a String.

If handler is a:

  1. Method of this instance -> use this method.
  2. A registered signal handler -> use this handler.
  3. Otherwise -> create a new function that publishes this string as an event.

  4. If handler ends with '+' then it will be invoked with the arguments sent to it as its parameters.

  5. If handler starts with a '-' then it will be published as global event with the <id>. prefix.
Name Type Description
handler string | function

a handler or a string representation of a handler.

parsed handler.

inherited private_setCloak(cloak){Widget}

widgets/Base.js, line 910

Toggles the element's visibility, depending on the cloak argument. If the hide option is truthy it will toggle the hide class instead, based on the cloak argument.

Used for hiding the widget from view while it is asleep.

If cloak is truthy the element will be hidden and otherwise shown. The hide class is located in the uijet's stylesheets in layout.less.

Related options:

  • hide: if truthy this method will toggle the hide class.
  • cloak: if truthy, and hide option is falsy, this method will toggle the visibility style attribute of this element.
Name Type Description
cloak boolean optional

whether to cloak the element.

inherited private_setResource(){uijet.Base}

uijet.js, line 725

Assigns the resource to this.resource.

Related options:

  • resource: a name of a registered resource or an object to use as a resource.
  • resource_name: a key to use when referencing the model's attributes form the context object. Defaults to the resource option if it's a string, otherwise to '<>_data'.

inherited private_wrap(){Widget}

widgets/Base.js, line 841

Utility for wrapping the widget's element in a container element.

Related options:

  • dont_wrap: skips wrapping and sets $wrapper to $element.
  • wrapper_class: extra class names to be set on the container element.
  • wrapper_tag: a name of a tag to use for the container element. Defaults to div.
  • cloak: if this instance is cloaked, hiding is transferred to the container.
  • hide: if this instance is hidden, hiding is transferred to the container.

inherited appear(){Widget}

widgets/Base.js, line 474

Makes the instance's element appear in the UI. By default this only calls BaseWidget#_setCloak which toggles visibility.


  • pre_appear: triggered at the beginning.
  • post_appear: triggered at the end.

inherited bind(type, handler){Widget}

widgets/Base.js, line 519

Binds handler to an event specified by type on the instance's element. Inside the handler this refers the instance, and has the same parameters as an event handler of the used DOM module.

type may contain a query selector, space separated, for a descendant target element of this.$element for delegating the event from that target only.

handler can be a name of a method of the instance, a type of a signal that has a handler connected to it, or as a default a topic that will be published as an app_event.

Name Type Description
type string

the type of the event to bind to.

handler function | string

the event handler or a string that represents it.

inherited bindAll(){Widget}

widgets/Base.js, line 577

Binds all DOM events that were initially in the instance's config or were later attached using BaseWidget#bind.


modules/data/backbone.js, line 62

Binds all data events set in options.data_events.

Supported events:

  • string: a name of a widget's method. Defaults to publishing an event that takes the arguments in a single array as the data param. Also respects the '-' prefix for global events.
  • function: a function to use as the handler.

Related options:

  • data_events: ths events to bind.

Related uijet options:

  • data_events: if the instance's data_events option is not set, this wii be used as default.


modules/data/backbone.js, line 156

If this resource is a Model also handles removing it from containing collection, or destroying it if asked to.

Related options:

  • destroy_resource: Tells the widget to call destroy() on its resource. Defaults to false.
  • remove_resource: Tells the widget to remove() its resource from its related collection. Defaults to false.

inherited destroyContained(){Widget}

widgets/Base.js, line 390

Cleans up all contained widgets using BaseWidget#destroy.

inherited disappear(){Widget}

widgets/Base.js, line 491

Makes the instance's element disappear from the UI.


  • post_disappear: triggered at the end.

inherited getContext(key){*}

widgets/Base.js, line 183

Gets the context object of the instance or the value of a specific property.

Name Type Description
key string optional

a name of a property in the context object.

value of the key or the context object.

inherited holdSignal(topic){uijet.Base}

uijet.js, line 637

Holds a signal's handler from being triggered.

Name Type Description
topic string

the name of the signal to hold.

inherited init(options){Promise}

widgets/Base.js, line 116

Initializes a widget instance and returns a list

A lifecycle method, does all the possible lifting that can be done before awaking/rendering.

init() is invoked by uijet when it is init()ed itself or when you start() a widget ad-hoc.


  • post_init: triggered at the end of this method.

Related options:

  • bind_on_wake: unless true all dom_events will be bound to the this.$element at the end of this method and before post_init signal is triggered.
Name Type Description
options Object

config object for the widget.

inherited initContained(){Promise}

widgets/Base.js, line 161

Initializes contained widget instances. Returns a Promise that resolves once all contained components finish initializing.

If the container option of the contained widgets is not set, it will be automatically set to the id of this widget.

Related options:

  • components: list of contained components to init.

inherited listen(topic, handler){uijet.Base}

uijet.js, line 575

Registers a handler for the given type.

Name Type Description
topic string

the signal's type to register.

handler function

the signal's handler to register.

inherited notify(once, topic, args){*}

uijet.js, line 614

Triggers a signal of the given type and returns the result of its call. If no handler was registered for that signal returns undefined. If the first argument is a Boolean it is used to determine whether to make sure this signal is triggered once during current lifecycle stage. {@see Base} does not define a _finally method that is used to clean up these "once" states.

Name Type Description
once boolean optional

optional true flag to make sure this signal is notified once per lifecycle stage.

topic string

the name of the signal to notify.

args * optional repeatable

arguments to hand over to the signal's handler.

result of the triggered handler or undefined.

inherited position(position){Widget}

widgets/Base.js, line 436

Minimal version of extension/position#position that only handles the value 'center' for the position option for centering an instance's element.

This method will always attempt to BaseWidget#_wrap the instance's element.

Name Type Description
position string

directives for positioning the instance's container element.

inherited prepareElement(){Widget}

widgets/Base.js, line 410

Initializes the instance's element.

Related options:

  • type_class: classes that define the type of the widget's component and are set on the elements class attribute.
  • extra_class: space separated class names to be added to the element's class attribute.
  • position: string|Object to be passed to BaseWidget#position.
  • style: string|Array|Object to be passed to BaseWidget#style.

inherited publish(topic, data){uijet.Base}

uijet.js, line 721

Triggers an event of given type topic. If data is supplied it is handed over to the handler as an argument. topic is always prefixed with + '.'.

Name Type Description
topic string

the type of the event to trigger.

data * optional

argument to pass to the event's handler as data.


modules/data/backbone.js, line 42

Binds data_events of the resource to the instance.

Related options:

  • dont_bind_data_events: used internally to delay auto-binding of data_events to allow binding those later manually. Normally you should not touch this option.

inherited releaseSignal(topic){*}

uijet.js, line 662

Releases and triggers a held signal. The handler is invoked with the arguments it was provided with on previous calls to Base#notify with same topic.

Name Type Description
topic string

the signal to release and trigger.

result of signal handler's call.

inherited remove(reinsert){Widget|HtmlElement}

widgets/Base.js, line 738

Removes the instance element (including wrapper) from the DOM. If you wish to later insert it back to the DOM pass true as the reinsert parameter. In such case the removed element will be returned.

Name Type Description
reinsert boolean optional

set to true if removed element is to be reinserted back to the DOM.

removed element if reinsert is true, otherwise this.

inherited render(){Widget}

widgets/Base.js, line 457

Placeholder for rendering logic.


  • pre_render: triggered at the beginning.

inherited setContext(ctx, value){Widget}

widgets/Base.js, line 196

Sets properties on the context object. Either using a map of properties or key and a value.

Name Type Description
ctx Object | string

a map of properties to set on the context or a name of a property to set.

value optional

if ctx is a string representing a key the this will be its value.

inherited setElement(element){Widget}

widgets/Base.js, line 716

Sets this.$element.

Related options:

  • element: the element to use as either query selector, element object, wrapped element, or a function returning one of the above.
Name Type Description
element string | HTMLElement | Array.<HTMLElement>

query selector, element, or wrapped element to use as the instance's element.

inherited setId(){Widget}

widgets/Base.js, line 696


First attempts to check options, then falls back to the element's id attribute, then to calling BaseWidget#_generateId.

Related options:

  • id: the id to use.

inherited setInitOptions(){Widget}

widgets/Base.js, line 647

Perform initialization tasks based on this.options.

Related options:

inherited setOptions(options){Widget}

widgets/Base.js, line 622

Sets this.options based on class's defaults and instance's declaration.

Name Type Description
options Object

options set in instance declaration's config.

setResource(resource, resource_name){Widget}

modules/data/backbone.js, line 131

Sets a given resource instance to this widget, and also updates resources registry, so that all other widgets requesting this resource get it.

Related options:

  • resource: used as the default for resource_name param.
Name Type Description
resource Model | Collection

a new instance of a resource to use as this widget's resource. Also updates registry with this instance.

resource_name string optional

the name this resource is to be registered under. Defaults to this.options.resource.

inherited sleep(no_transitions){Widget}

widgets/Base.js, line 323

Stops a started widget. A lifecycle method, hides the widget and removes all DOM events from it. Every contained widget will also be stopped and this will continue trickling down recursively.

Related options:

  • destroy_on_sleep: if true this widget will self destruct when put to sleep.


  • pre_sleep: triggered at the beginning of this instance is awake.
  • post_sleep: triggered at the end of this instance is awake.
  • bind_on_wake: if true all dom_events will be unbound from the this.$element on every sleep.
Name Type Description
no_transitions boolean optional

whether to use a transition, if specified, for hiding.

inherited sleepContained(){Widget}

widgets/Base.js, line 352

Stops contained widgets.

inherited subscribe(topic, handler){uijet.Base}

uijet.js, line 685

Registers the given handler under the given type topic. If handler is a Function it is bound to this instance as its context. If handler is a String it is used to find a method of same name to use as handler. If no method was found then a signal with same type's handler is used. If handler is a String and ends with a '+' then the arguments supplied to this handler will be passed to that method/signal handler.

Name Type Description
topic string

the type of the handler to register.

handler function | string

the handler to register or a name of a method of this instance or a signal's handler to use as handler.

inherited trickle(context){Widget}

widgets/Base.js, line 209

Sets properties on the contained components of this widget. This effect will continue to propagate recursively.

Name Type Description
context object optional

a map of properties to send to contained widgets to set on their context. Defaults to the result of this.getContext().

inherited unbind(type, selector, handler){Widget}

widgets/Base.js, line 554

Unbinds a specific handler or all handlers from the event of type type, either delegated from a descendant or straight from this.$element.

type may also contain the selector argument in it, separated by whitespace from the type. In such case, the second argument should be the handler.

Name Type Description
type string

type of event to unbind.

selector string optional

query selector for filtering a descendant in case of unbinding event delegation.

handler function

a reference to the handler function.

inherited unbindAll(){Widget}

widgets/Base.js, line 601

Removes all attached DOM events that were initially in the instance's config or were later attached using BaseWidget#bind.


modules/data/backbone.js, line 119

Unbinds all data events handlers registered with this instance.

Name Type Description
resource Model | Collection optional

a resource to stop listening to. Defaults to this.resource.


inherited unlisten(topic){uijet.Base}

uijet.js, line 588

Removes a handler of the given type. If no topic is given then removes all handlers.

Name Type Description
topic string optional

the signal's type to remove.

inherited unregister(){uijet.Base}

uijet.js, line 555

Unregisters the widget from uijet's sandbox.

inherited unsubscribe(topic, handler){uijet.Base}

uijet.js, line 702

Removes a handler from the registered events. If handler is not supplied then the handler that is currently registered for the given topic is used.

Name Type Description
topic string

the event type to remove from registry.

handler function optional

the handler to remove from the registry.

inherited wake(context){Promise}

widgets/Base.js, line 243

Starts up the widget. A lifecycle method, renders the widget, attaches all DOM events to it and brings it into view. Every widget also wakes its contained widgets, so this triggers a recursive action that wakes the whole widgets branch downwards.

Takes an optional context parameter that will be passed to BaseWidget#setContext if it is an Object, to pre_wake and post_wake signals and to BaseWidget#wakeContained.


  • pre_wake: triggered before waking of contained widgets, takes wake()'s context param as argument. If it returns false the instance will not call BaseWidget#render.
  • post_wake: triggered at the end of a successful wake, takes wake()'s context param as argument.
  • wake_failed: triggered at the end of a failed wake, takes all arguments of the rejected BaseWidget#wakeContained, or render() call. If it returns a truthy value wake() will be invoked again, otherwise sleep().

Related options:

  • sync: when true a successful starting sequence will only begin once all promises returned by wake() calls of all child components are resolved. Otherwise, will start immediately.
  • bind_on_wake: if true all dom_events will be bound to the this.$element on every wake.
Name Type Description
context * optional

possibly an Object containing properties to set on the context.

when all contained widgets successfully wake or rejected in case of error.

inherited wakeContained(context){Array.<Promise>}

widgets/Base.js, line 298

Wakes up contained widgets.

Takes an optional context argument that is passed to the BaseWidget#wake calls of the contained widgets.

Name Type Description
context * optional

optional context for contained widgets.