![]() Instead of listening and responding to Backbone model change events directly, app objects (including Backbone models and views) use the JS Actions API as the primary method for exchanging information in relation to state changes and other events. The Dispatcher listens to key model events and triggers actions in response to these events. The code is structured using a number of JS object classes that: i) act as containers of the associated Backbone models/views and ii) provide methods for accessing key properties associated with the concepts they abstract (Composite, Step, Component).Ī key element of the single-page app is the Actions Dispatcher, which implements a simplified JavaScript version of the WordPress Actions API ( do_action, add_action, remove_action). The app relies on the Backbone.js stack in order to maintain its internal state and update its views. ![]() ![]() It is responsible for tasks such as loading/filtering/appending Component Options, presenting selected product details, validating selections, displaying validation messages, calculating and displaying totals, summarizing selections, updating browser history when navigating between Components, etc. The Composite Products single-page JavaScript app handles all front-end functionality associated with configuring a Composite product and interacting with its Components. The app’s source code is built into a single file, /assets/js/add-to-cart-composite.js – the minified version of this file, /assets/js/, is the one enqueued by the extension. If you want to try this sample plugin, you can find it here, and, just in case you are interested, you can debug the JS code at my website homepage, where this sample plugin is already installed (WP version is 4.8beta2 as of time of this writing).Elementor Connector for WooCommerce BookingsĪll Products for WooCommerce Subscriptionsīulk Updater for WooCommerce Subscriptions It turned out it's NOT a WP bug, so this question still needs an answer, but Adam, who replied to my bug report, gave us some valuable informations.Īs for the suggestion birgire gave in comments, unfortunately I have no clue about how to use the QUnit code, maybe you can walk me through that? I thought it could be a WP bug (maybe a documentation bug), and I opened a bug report. My JS file (ies.js) is not even mentioned in the stack trace of the 4.7.x exception, while in 4.8beta2 it seems a simple syntax error, but I don't know how should I otherwise call my endpoint. The same code, using WP 4.8beta2, seems to work at least until it reaches the wp.api.namespace() call, where I get: Uncaught TypeError: wp.api.namespace is not a functionĪt Object.e.(anonymous function) () However this JS code, in WP 4.7.4/4.7.5, throws an exception in the JS console after the call to wp.api.init() and before it reaches the call to wp.api.loadPromise(): Uncaught TypeError: _.includes is not a functionĪt Function.h.each.h.forEach (underscore-min.js?ver=4.7.4:1)Īt Object.wp. (?ver=4.7.4:1)Īt n.constructFromSchema (?ver=4.7.4:1) Wp.api.namespace(ies_rest.namespace).istermactive().done(function (active) Wp_localize_script($handle, "ies_rest", $local_data) Īnd here is the ies.js code: (function( $ ) ).done(function() $local_data = array('apiRoot' => get_rest_url(), "namespace" => $this->namespace) ![]() Wp_register_script($handle, $jsfileurl, array("underscore", "backbone", "wp-api")) 'callback' => array($this, 'istermactive') The filename is rest-api-sample.php: namespace, Here is the PHP code of a sample plugin I've just written to show my issue. I'm trying to figure out how I should call a REST API custom endpoint from the JS code of a plugin.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |