The App variable is accessible globally as a result of the codelation_ui/base
package. The most important part of this variable is the register
function. This works in tandum with Turbolinks to run javascript in different orders and only on certain pages.
If you would like to run a script on only the products/index
page, you would simply wrap your javascript in the following:
App.register('products.index').enter(function(){
// your code
}).exit(function(){
// run code when the page leaves (WILL NOT STOP THE PAGE FROM REDIRECTING)
});
Additionally, you can run code for any of the products
page with:
App.register('products').enter(function(){
// your code
});
As of Version 1.1.0, this now allows for nested controllers/routes. For example, you may nest a categories controller under your products controller actions and run code for only that with:
App.register('products.categories.index').enter(function(){
// your code
});
If you would like to run javascript on any page, this is considered a component
. Here is how to define it:
App.register('component').enter(function(){
// your code
});
Sometimes you need to run code before any of your other scripts run. This is useful for things like setting up vue components that other page wise components depend on.
App.register('first').enter(function(){
// your code
});
Likewise, you can also specify a script to run last.
App.register('last').enter(function(){
// your code
});
The config option to the register method allows for javascript to be run before any other registered scripts. Why have both first
and config
? First is great for setting up components and such, but what if those depend on some configuration options? That is where this is useful. Generally this is where you will set options in the App.ui.config
object.
App.register('config').enter(function(){
// your code
});
By default, the UI object is outputted to the warnings console. This object lives under the App object like the following: App.ui
. This is structured as following:
App.ui = {
interfaces: {
_info: 'Used for containing mixins and methods used for vue'
},
computedInterfaces: {
_info: 'Same as interfaces except accepts arguments to alter the mixin before applying it to the component'
},
globalComponents: {
_info: 'Used to define all global components'
},
components: {
_info: 'Used to hold references to various vue components you may use or are not defined globaly'
},
config: {
_info: 'Used to customize the functionality for some interfaces and components',
main: {
showInterfaces: true,
includedInterfaces: []
}
},
root: null, // Used to hold the reference to the root vue instance, if not found, it will define one
extend: {
_info: 'Used to hold references to per page components and attach to the root component if you did not define one.'
}
}