rails-js-routes
rails-js-routes copied to clipboard
Extended Turbolinks support
Support of page:before-unload
event
Approach:
Each route (e.g. users#edit
) isn't stored as a function, but as a Hash/Object.
So if necessary a route can be defined such as:
/*
* app/assets/javascripts/controllers/users.js
*/
Rails.controller('users', {
index: function(h) {
},
edit: {
load: function() {
// ...
},
unload: function() {
// ...
}
}
});
Maybe on
/ off
/*
* app/assets/javascripts/controllers/users.js
*/
Rails.controller('users', {
index: function(h) {
},
edit: {
on: function() {
// ...
},
off: function() {
// ...
}
}
});
This might confuse people, which usage scope this function have.
on
/off
is kinda reserved for events only, but users.edit.on
would have all the buildup code (e.g. showing/hiding something), while off
is just unbinding events.
For example if you want to unset some window
binding library (e.g. leaflet), because you just need it on one out of hundert routes.
But yeah, basically that's naming, so let's explore how others tackle to get a convenience.