This repository has been archived by the owner. 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

Comments

Projects
None yet
3 participants
@joostverdoorn
Member

joostverdoorn commented Jun 26, 2014

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

This comment has been minimized.

Show comment
Hide comment
@steffansluis

steffansluis Aug 2, 2014

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!

Collaborator

steffansluis commented Aug 2, 2014

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

This comment has been minimized.

Show comment
Hide comment
@rogierslag

rogierslag Aug 3, 2014

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

Member

rogierslag commented Aug 3, 2014

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

@rogierslag rogierslag closed this Aug 3, 2014

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.