Opened 7 years ago
Last modified 6 years ago
#42737 assigned feature request
Add method wp.api.getModelByType for retrieving api models
Reported by: | mkaz | Owned by: | adamsilverstein |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 5.1 |
Component: | REST API | Keywords: | needs-patch |
Focuses: | javascript | Cc: |
Description
For Gutenberg, it will be easier and less error prone to fetch the wp.api.model by retrieving by type instead of creating a route and searching for the model that matches that route.
An open detail to work out is if namespacing is needed, can objects have the same name in different API namespaces in the same instance of wp.api. A potential solution could be an optional second argument.
For example: getModelByType( type, versionString = 'wp/v2' )
Related to #41111
Original Slack Discussion at:
https://wordpress.slack.com/archives/C5UNMSU4R/p1511878493000062
Attachments (1)
Change History (8)
This ticket was mentioned in Slack in #core-js by mkaz. View the logs.
7 years ago
#5
@
7 years ago
Patch attached.
The mapping associative arrays were created outside of the getModelByType and getCollectionByType functions so that they can be extended or overwritten if necessary.
#6
@
7 years ago
This is no longer needed to support Gutenberg, the calls were changed to no longer map into Backbone models but to go straight to the API for data.
Change made in https://github.com/WordPress/gutenberg/pull/5253
I still think this change is better way to map models instead of the routes which can lead to error, but probably doesn't make sense to include if there isn't going to be any code to use the new functions.
The reference implementation is available at PR #3683 on Gutenberg
https://github.com/WordPress/gutenberg/pull/3683