If you’ve been reading through my Advanced Javascript, UI Components, and uiElement Internals series, you’re aware that Magento have extended the Knockout.js template system such that Templates can be Loaded via ajax/HTTP Knockout’s “tag-less” bindings have tag equivalents The remote HTTP templates are a [...]
astorm
Back when Magento 2 was released, I noticed the much touted API didn’t have a method for fetching a product’s canonical URL. A year later that’s still the case. Magento’s reasoning and response, both from an engineering perspective and a product perspective points to a big cultural problem that goes beyond this [...]
astorm
Magento 2: Are uiClass/uiElement Imports/Exports order sensitive? The answer is mostly no. Imports/Exports values are fetched via the uiRegistry.get’s asynchronous callback method which means if the imports or exports attempts to access an item that doesn’t exist yet in the registry, the system will “wait” until [...]
astorm
Magento 2: Extract Currently Selected Product ID or SKU on Product Page Rian managed to dig up most of the data embedded in a Magento 2 product listing page that would let a programmer extract the Product ID of the currently selected product on a configurable product page. I threw together this quick RequireJS program that shows how you [...]
astorm
If you’re following along with my UI Component and uiElement Internals series, you know about Magento’s uiRegistry module. You can use this module to fetch the scoped Knockout.js view models by registered name requirejs(['uiRegistry'], function(reg){ console.log( reg.get('customer') ); }); or by using a callback function to [...]
astorm
That I’m posting this as a quickie probably points to the amount of time I’m spending with Magento 2’s internals vs. building out client sites, but I still haven’t internalized that Magento moved the the Design configuration options from Stores -> Configuration -> Design to Content -> Design -> [...]
astorm
Time to Report Bug: Two Weeks Over on alanstorm.com we’re in the middle of a series covering the internal implementation of uiElement objects. This series was prompted by some strange behavior in the default value system w/r/t observable objects. The linked bug report covers the details of why this happens, and why it’s a [...]
astorm
Be Careful with the “new-less” form of uiClass object instantiation Last time we said Magento’s uiClass based objects don’t require the new keyword. This is true. However, when you’re using the inheritance features of these objects its possible to supply a custom constructor. If you do this, and your custom [...]
astorm
In doing research for the new uElement Internals series, I discovered that Magento’s UI Component object constructors (uiClass, uiElement, uiCollection, etc) can create new objects without the use of the new keyword. //both return a new `UiElement` object object = new UiElement; object = UiElement(); This makes these constructor [...]
astorm
@api coverage for Magento 2 Javascript According to this forum thread from one of Magento 2’s architects, it sounds like Magento 2.2 is going to bring @api style coverage to Magento’s RequireJS module. This is a positive step in that it will clarify which javascript functions we can rely on working version to version. This is [...]
astorm
Wrapping up our uiElement defaults, we have the registerNodes defaults #File: vendor/magento/module-ui/view/base/web/js/lib/core/element/element.js defaults:{ /* ... */ registerNodes: true, /* ... */ } This is another node that you don’t need to worry too much about. Magento uses this to identify the uiElement objects in the [...]
astorm
Two defaults you don’t need to worry too much about are the containers and _requested defaults. #File: vendor/magento/module-ui/view/base/web/js/lib/core/element/element.js defaults: { _requesetd: {}, containers: [], /* ... */ } These are just properties that Magento’s initializing using the uiElement’s defaults [...]
astorm
The name and ns defaults #File: vendor/magento/module-ui/view/base/web/js/lib/core/element/element.js defaults: { /* ... */ name: '', ns: '${ $.name.split(".")[0] }', /* ... */ } are another pair of defaults that don’t make a lot of sense in the context of a traditional programming object system. Like the provider default, the name [...]
astorm
The next two defaults we’ll blitz through are the provider and source defaults. #File: vendor/magento/module-ui/view/base/web/js/lib/core/element/element.js defaults:{ /* ... */ provider: '', /* ... */ source: null, /* ... */ } We’re starting to get into the defaults that are tricky to understand since they involve both a [...]
astorm
The next uiElement default we’re going to talk about is the statefull default. Before we begin, let us bask is the programmer’s glory of the misspelling of “stateful” making it into a production release. The statefull default allows you to create a uiElement object with properties that will be automatically [...]
astorm
Earlier, we described the modules defaults for Magento uiElement javascript constructor functions. If you look at the uiElement definition, you’ll see there’s one modules default already configured for all uiElements #File: vendor/magento/module-ui/view/base/web/js/lib/core/element/element.js modules: { storage: '${ [...]
astorm
One Magento uiElement default you don’t need to worry about is the maps default, seen here in uiElement’s source file #File: vendor/magento/module-ui/view/base/web/js/lib/core/element/element.js defaults:{ /* ... */ maps: { imports: {}, exports: {} }, /* ... */ } This isn’t a magic default, it’s just the uiElement [...]
astorm
Continuing in our informal series of quickies explaining the more magical defaults properties of Magento uiElement objects, today we’ll explore the modules default. The modules default allows you to link a property in your new object with an object in Magento’s uiRegistry via the registry’s “async” feature. [...]
astorm
Another quick post on another defaults entry for Magento’s uiElement javascript class/constructor function. Before we can talk about listens though, we’ll need to quickly review imports. In your Magento backend, navigate to the customer listing grid at Customers -> All Customers in Magento’s backend. Then, in your [...]
astorm
Every uiElement based object has an observe method. This method allows you to turn any value into a Knockout.js observable. UiElement = requirejs('uiElement'); object = new UiElement; object.foo = 'bar'; object.observe('foo'); console.log(object.foo()); As you can see from the above, we’ve turned the foo property, formerly a [...]
astorm