Skip to content
This repository was archived by the owner on Nov 28, 2017. It is now read-only.

Interceptable: intercept methods before constructor, not just before initialize when passing a function #7

Closed
joostverdoorn opened this issue Jun 26, 2014 · 2 comments
Labels

Comments

@joostverdoorn
Copy link
Member

There are some cases where intercepting methods are too late when passing functions:

class MyRouter extends Backbone.Router
  _.extend @, Tails.Mixable

  @concern Tails.Mixins.Interceptable

  @before -> these: ['friends', 'account'], do: 'ensureSignedIn'
  @before -> admin: 'ensureAdmin'

  routes: 
    '/friends': 'friends'
    '/account': 'account'
    '/admin':   'admin'

  products: ( ) ->
  account: ( ) ->
  admin: ( ) ->
  ensureSignedIn: ( ) ->
  ensureAdmin: ( ) ->

This is not gonna work. Backbone extracts the methods for its routes in the constructor, whereas the interceptors are applied just before the initialize method is run. It would be nice if, without actually defining a constructor, we could run code before it is run.

@steffansluis
Copy link
Collaborator

CoffeeScript uses the constructor to generate class inheritance, but that inadvertently also means you can't wrap constructor (easily). The only not really viable solution I see is injecting a method in between every inheritance relation in the application as the first thing we do. The alternative is try and amend CoffeeScript because that went so well last time!

@rogierslag
Copy link
Member

The only not really viable solution I see is injecting a method in between every inheritance relation in the application as the first thing we do.

That's gonna cause a huge overhead I'm afraid

The alternative is try and amend CoffeeScript because that went so well last time!

#sarcasm

I'm closing this now, don't see how we can get any further with this within the next few weeks/months

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants