This repository has been archived by the owner on Sep 5, 2018. It is now read-only.
Create models before DOM ready if possible; add promises for when schema constructs #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The changes here will ensure that the Backbone models for the WPI API will be constructed before DOM ready if the JS is enqueued via WordPress so that the schema can be exported as script data. If the schema is not available in the initial PHP response, it will fallback to looking for a schema in
sessionStorage
. Otherwise, it will fetch the schema from the server.The
wp.api.init()
function now returns a promise which resolves when the models are constructed and extended ontowp.api.models
andwp.api.collections
. Thiswp.api.init()
function also takes anargs
param which allows you to initialize additional endpoints other than the default (which is initialized automatically). For example:Calling
wp.api.init()
repeatedly for a given endpoint will only initialize the route once: the same promise will be returned for each invocation.This introduces a new
Endpoint
model which contains aSchema
model instance. I'm not 100% confident with how these are are organized.