Skip to content

Commit

Permalink
Fix DI bug with view prototype inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkoretskiy committed Aug 27, 2014
1 parent 956d10c commit e23da53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dist/backbone-mixin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ MixinBackbone = (Backbone)->
@_$_p.diViews[key] = ViewClass
else if typeof(ViewClass) is "function"
TypeView = ViewClass
key = TypeView::_$_di or (TypeView::_$_di = _.uniqueId("_$_di"))
key = TypeView._$_di or (TypeView._$_di = _.uniqueId("_$_di"))
else
TypeView = ViewClass.type
TypeView::_$_di or (TypeView::_$_di = _.uniqueId("_$_di"))
TypeView._$_di or (TypeView._$_di = _.uniqueId("_$_di"))
key = ViewClass.key
diview = @_$_p.diViews[key]
removeFlag = !!diview?._$_p?.removeFlag
Expand Down
8 changes: 7 additions & 1 deletion test/check-DI-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe "Check MixinBackbone DI",->
keys = @view._diViewsKeys()
values = @view._diViewsValues()
expect(1).toBe _.size(keys)
expect(@TestViewDI::_$_di).toBe keys[0]
expect(@TestViewDI._$_di).toBe keys[0]
expect(1).toBe _.size(values)
expect(view1).toBe values[0]

Expand All @@ -54,4 +54,10 @@ describe "Check MixinBackbone DI",->
view2 = @view.getViewDI @TestViewDI
expect(view2?._$_p?.removeFlag).toBe false

it "correct work with prototype inheritance", ->
ParentView = Backbone.View.extend {}
ChildView = ParentView.extend {}

parentView = @view.getViewDI ParentView
childView = @view.getViewDI ChildView
expect(parentView).not.toBe childView

0 comments on commit e23da53

Please sign in to comment.