Skip to content
This repository has been archived by the owner on Jan 12, 2018. It is now read-only.

Commit

Permalink
Don't call loaded callback from custom helpers if it is inherited
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed Sep 20, 2013
1 parent ceedecc commit 37b8ab7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ Compile =

helper: (ast, model, controller) ->
dynamic = new DynamicNode(ast)
renderBlock = (model=model, controller=controller) ->
new View(null, ast.children).render(model, controller)
renderBlock = (model=model, blockController=controller) ->
new View(null, ast.children).render(model, blockController, controller, controller is blockController)
helperFunction = Serenade.Helpers[ast.command] or throw SyntaxError "no helper #{ast.command} defined"
context = { model, controller, render: renderBlock }
update = ->
Expand Down
26 changes: 26 additions & 0 deletions test/integration/custom_helper.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,29 @@ describe 'Custom helpers', ->
expect(@body).to.have.element('div > #foo')
expect(@body).to.have.element('div > #quox')
expect(@body).not.to.have.element('div > #test')

it "calls loaded callback if controller is new", ->
funked = null
class TestCon
loaded: -> funked = 'foo'

Serenade.Helpers.funky = -> @render({}, TestCon)

@render '''
ul
- funky
'''
expect(funked).to.eql('foo')

it "does not call loaded callback if controller is inherited", ->
funked = 0
class TestCon
loaded: -> funked += 1

Serenade.Helpers.funky = -> @render({}, @controller)

@render '''
ul
- funky
''', {}, TestCon
expect(funked).to.eql(1)

0 comments on commit 37b8ab7

Please sign in to comment.