Skip to content
Brian Cavalier edited this page Mar 23, 2012 · 4 revisions

wire/dojo/store

The wire/dojo/store plugin uses wire.js's JSON-reference-like syntax to provide an easy way to create and inject Dojo's JsonRest stores. You can also directly inject the results doing a get() or query() on a store--either waiting for the concrete results, or injecting the promise that JsonRest returns.

Because JsonRest stores are just regular Javascript objects, you could create them using the create factory, but using this plugin gives you a shortcut, and also allows you to inject direct references to data items and query results.

Options

{
	module: 'wire/dojo/store'

	// Easy!  There are no options, just include the plugin.
}

resource! References

Syntax

The following is a reference to a JsonRest store whose target is the REST endpoing at url/of/jsonrest/target.

{ $ref: 'resource!url/of/jsonrest/target' }

You can also specify the idProperty JsonRest option directly in the options:

{ $ref: 'resource!url/of/jsonrest/target', idProperty: 'idFieldName' }

Using the get option, you can fetch a particular item by id from a REST endpoint. If wait is false (the default), this will be a reference to the promise returned by get(). If wait is true, this will be a reference to the actual data item with the specified id.

{ $ref: 'resource!url/of/jsonrest/target', get: 123, wait: false /* or true */ }

Using the query option, you can query the REST endpoint and inject the results. If wait is false (the default), this will be a reference to the promise returned by query(). If wait is true, this will be a reference to the actual data array.

{ $ref: 'resource!url/of/jsonrest/target', query: { name: 'Bob' }, wait: false /* or true */ }

Notes on using wait: true

tl;dr You should use wait: false whenever possible.

Wiring is a typically highly asynchronous operation, and wire.js is very aggressive in getting as many asynchronous operations (for example: plugin and module loading, reference resolution, etc.) into flight as early as possible. Then, as those operations complete, it finalizes components that depend on completed async operations. When all components have been finalized, wiring is complete.

Using the resource! resolver's wait: true causes wire.js to wait for the underlying XHR to complete before considering the reference to be resolved. Thus, wiring will not complete until the XHR has completed.

Letting wait default to false (or setting it explicitly), allows wiring to complete before the underlying XHR has completed.

Clone this wiki locally