rails-js-routes icon indicating copy to clipboard operation
rails-js-routes copied to clipboard

Extended Turbolinks support

Open tonekk opened this issue 10 years ago • 3 comments

Support of page:before-unload event

tonekk avatar Nov 26 '14 12:11 tonekk

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() {
      // ...
    }
  }
});

zcei avatar Nov 26 '14 13:11 zcei

Maybe on / off

/*
 * app/assets/javascripts/controllers/users.js
 */

Rails.controller('users', {

  index: function(h) {

  },

  edit: {
    on: function() {
      // ...
    },
    off: function() {
      // ...
    }
  }
});

tonekk avatar Nov 26 '14 13:11 tonekk

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.

zcei avatar Nov 26 '14 13:11 zcei