Implement an opt-in improved JS framework (Snowboard)#354
Implement an opt-in improved JS framework (Snowboard)#354bennothommo wants to merge 114 commits intowip/1.2from
Conversation
This reverts commit e9d928a.
This reverts commit 0affd78.
…nto wip/framework-rewrite
- Sets up architecture of new framework - Provides some global utilities - JSON Parser, HTML sanitizer and debouncer (similar to Vue.nextTick) - Defines a new JS Request handler using "fetch()" to make AJAX calls - Defines a new optional "EnableDataRequest" extension to enable AJAX framework through data attributes
I'm of the opposite opinion. I find it instantly more readable for the Snowboard tag to include which features it is using. If I'm looking at a couple of themes, I feel it would be easier to see I don't think it'll be a friction for people to have to explicitly add which features they want to use (or use |
|
Work continued in #401 to target the 1.1.8 release. |
REPLACED BY #401
Documentation: wintercms/docs#45
This PR moves towards introducing a new JavaScript framework for Winter, that uses modern JavaScript and removes the hard-dependency to jQuery that has traditionally been the case with Winter and October before it.
If accepted, we intend to make this opt-in, and still provide the option of using the original framework for legacy apps and older browser support.
Goals
Concepts
The four cornerstones of this framework are as follows:
The
SnowboardclassRepresents the global container for the application. This stores all activated plugins and provides instances of these modules as required. It is synonymous with the
Applicationclass of Laravel, or aVueinstance.The
PluginLoaderclassThe main conduit between a plugin and the Snowboard app. This provides the mechanism for delivering instances of each module (or a single instance of Singleton plugin) and resolves dependencies.
The
PluginBaseclassA plugin is a specific extension to the Snowboard application. It can contain code that provides new functionality or augments other functionality already registered in the application. A plugin can be reused - in essence, each call to the plugin will create a new instance and will be independent from other instances. This would be used for scenarios such as Flash messages, AJAX requests and the like.
The
SingletonclassAn extension of the
PluginBaseclass. It signifies to the application that this plugin should exist once, and all uses of this plugin should use the same instance. This would be useful for things like event handlers, extending functionality of another plugin or global functionality.A singleton is initialized automatically when the DOM is ready, if it is called directly or if it listens to an event that is fired. The singleton instance is then used no matter how many times it is called from the Snowboard class.
What's included
By default, this framework only includes the framework architecture and a couple of utilities. This is an intentional choice to allow the greatest flexibility in how the framework is used. The utilities include:
Vue.newTickfunction in allowing code to run after the previous frame is rendered - useful for ensuring DOM changes are made and events are correctly fired.In addition, some opt-in features include a rewritten
Requestclass that represents a fresh take on the JavaScript AJAX framework available in Winter. This newRequestclass leverages thefetchmethod in all modern browsers to conduct AJAX calls. It supports all options and configuration that were previously available in the original framework.A second extension -
AttributeRequest- provides an augmentation to this functionality and allow the AJAX framework to also handle AJAX calls that use thedata-attributes. By separating these features, the developer has the ability to turn off support for thedata-attribute AJAX framework should they not need it.What's not included
data-attribute callbacks (eg.data-request-success,data-request-erroretc.). This feature, at a minimum, prevented sites using content security policies because of its use of theeval()method in JavaScript - at worst, it presented a potential vector for naughtiness. We will not be including this in the framework.Further notes
To-do