Skip to content

Commit b3ef9d9

Browse files
committed
New Mounting API
1 parent 458ec67 commit b3ef9d9

File tree

8 files changed

+28
-18
lines changed

8 files changed

+28
-18
lines changed

src/ReduxComponent.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ ReduxComponent.prototype.__willMount = (@store, @path = [], @parentComponent = n
2424
invariant(not @__mounted, "redux-component of type #{@displayName} was multiply initialized. This can indicate a cycle in your component graph, which is illegal. Make sure each instance is only used once in your tree. If you wish to use a component in multiple places, construct additional instances.")
2525
@__mounted = true
2626
@componentWillMount?()
27-
@reducer = indirectReducer.bind(@)
27+
#@reducer = indirectReducer.bind(@)
2828
@updateReducer()
2929

3030
ReduxComponent.prototype.__willUnmount = ->
3131
invariant(@__mounted, "redux-component of type #{@displayName} was unmounted when not mounted. This can indicate an issue in a dynamic reducer component such as redux-components-map.")
3232
@componentWillUnmount?()
33+
@__internalReducer = nullIdentity
3334
delete @__mounted

src/createClass.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ dontBindThese = {
77
updateReducer: true
88
__willMount: true
99
__willUnmount: true
10-
__mounter: true
1110
__init: true
1211
}
1312

src/index.coffee

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import applyMixin from './applyMixin'
22
import createClass from './createClass'
33
import DefaultMixin from './DefaultMixin'
4-
import mountComponent from './mountComponent'
4+
import { mountRootComponent, willMountComponent, didMountComponent, willUnmountComponent } from './mountComponent'
55
import ReduxComponent from './ReduxComponent'
66
import ObservableSelectorMixin from './ObservableSelectorMixin'
77
import { makeSelectorsObservable } from './makeSelectorObservable'
@@ -13,7 +13,10 @@ export {
1313
applyMixin
1414
createClass
1515
DefaultMixin
16-
mountComponent
16+
mountRootComponent
17+
willMountComponent
18+
didMountComponent
19+
willUnmountComponent
1720
ReduxComponent
1821
createComponent
1922
SubtreeMixin

src/mountComponent.coffee

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
defaultMounter = (store, componentInstance) ->
1+
export mountRootComponent = (store, componentInstance) ->
2+
componentInstance.__willMount(store, [], null)
23
store.replaceReducer(componentInstance.reducer)
4+
componentInstance.componentDidMount?()
35

4-
export default mountComponent = (store, componentInstance, path = [], mounter = defaultMounter) ->
5-
componentInstance.__mounter = mounter
6+
export willMountComponent = (store, componentInstance, path) ->
7+
componentInstance.__manualMount = true
68
componentInstance.__willMount(store, path, null)
7-
mounter?(store, componentInstance)
9+
componentInstance.reducer
10+
11+
export didMountComponent = (componentInstance) ->
812
componentInstance.componentDidMount?()
13+
14+
export willUnmountComponent = (componentInstance) ->
15+
componentInstance.__willUnmount()

test/01-basic.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ expect } = require 'chai'
22

3-
{ createClass, mountComponent, createComponent, SubtreeMixin } = require '..'
3+
{ createClass, mountRootComponent, createComponent, SubtreeMixin } = require '..'
44
{ makeAStore } = require './helpers/store'
55

66
describe 'basic functions: ', ->
@@ -25,7 +25,7 @@ describe 'basic functions: ', ->
2525

2626
it 'should mount instance of class on store', ->
2727
rootComponentInstance = new Subcomponent()
28-
mountComponent(store, rootComponentInstance)
28+
mountRootComponent(store, rootComponentInstance)
2929

3030
it 'should know about the store', ->
3131
expect(rootComponentInstance.store).to.equal(store)
@@ -60,7 +60,7 @@ describe 'basic functions: ', ->
6060

6161
it 'should mount instance of class on store', ->
6262
rootComponentInstance = new Subcomponent()
63-
mountComponent(store, rootComponentInstance)
63+
mountRootComponent(store, rootComponentInstance)
6464

6565
it 'should set the default state', ->
6666
expect(store.getState()).to.deep.equal({})

test/02-subtree.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{ inspect } = require 'util'
22

33
{ expect, assert } = require 'chai'
4-
{ createClass, mountComponent, createComponent, SubtreeMixin } = require '..'
4+
{ createClass, mountRootComponent, createComponent, SubtreeMixin } = require '..'
55
{ makeAStore } = require './helpers/store'
66

77
describe 'subtree: ', ->
@@ -37,7 +37,7 @@ describe 'subtree: ', ->
3737

3838
it 'should mount subcomponent using direct syntax', ->
3939
rootComponentInstance = createComponent( { foo: Subcomponent } )
40-
mountComponent(store, rootComponentInstance)
40+
mountRootComponent(store, rootComponentInstance)
4141

4242
describe 'complex: ', ->
4343
it 'should create new store', ->
@@ -65,7 +65,7 @@ describe 'subtree: ', ->
6565
rootComponentInstance = new RootComponent()
6666

6767
it 'should mount root instance on store', ->
68-
mountComponent(store, rootComponentInstance)
68+
mountRootComponent(store, rootComponentInstance)
6969

7070
it 'should print the whole component tree for your viewing pleasure', ->
7171
console.log(inspect(rootComponentInstance))

test/03-reducer-indirection.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{ createStore, applyMiddleware } = require 'redux'
55
ReduxDebug = require 'redux-debug'
66
ReduxFreeze = require 'redux-freeze'
7-
{ createClass, mountComponent, SubtreeMixin, createComponent } = require '..'
7+
{ createClass, mountRootComponent, SubtreeMixin, createComponent } = require '..'
88

99
describe 'reducer indirection: ', ->
1010
makeAStore = (initialState) -> createStore( ((x) -> x) , initialState, applyMiddleware(ReduxDebug(console.log), ReduxFreeze) )
@@ -45,7 +45,7 @@ describe 'reducer indirection: ', ->
4545

4646
it 'should mount subcomponent', ->
4747
rootComponentInstance = createComponent( { foo: Subcomponent } )
48-
mountComponent(store, rootComponentInstance)
48+
mountRootComponent(store, rootComponentInstance)
4949

5050
it 'should print the whole component tree for your viewing pleasure', ->
5151
console.log(inspect(rootComponentInstance))

test/04-observable-selectors.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{ inspect } = require 'util'
22

33
{ expect, assert } = require 'chai'
4-
{ createClass, mountComponent, createComponent, ObservableSelectorMixin } = require '..'
4+
{ createClass, mountRootComponent, createComponent, ObservableSelectorMixin } = require '..'
55
{ makeAStore } = require './helpers/store'
66

77
expectTestSequence = (tests) ->
@@ -48,7 +48,7 @@ describe 'observable selectors: ', ->
4848

4949
it 'should mount subcomponent', ->
5050
rootComponentInstance = createComponent( { foo: Subcomponent } )
51-
mountComponent(store, rootComponentInstance)
51+
mountRootComponent(store, rootComponentInstance)
5252

5353
it 'should print the whole component tree for your viewing pleasure', ->
5454
console.log(inspect(rootComponentInstance))

0 commit comments

Comments
 (0)