1
1
import invariant from 'invariant'
2
2
import React , { PropTypes } from 'react'
3
3
4
- const createBroadcast = ( initialValue ) => {
4
+ const createBroadcast = ( initialState ) => {
5
5
let listeners = [ ]
6
- let currentValue = initialValue
6
+ let currentState = initialState
7
7
8
- const getValue = ( ) =>
9
- currentValue
8
+ const getState = ( ) =>
9
+ currentState
10
10
11
- const setValue = ( value ) => {
12
- currentValue = value
13
- listeners . forEach ( listener => listener ( currentValue ) )
11
+ const setState = ( state ) => {
12
+ currentState = state
13
+ listeners . forEach ( listener => listener ( currentState ) )
14
14
}
15
15
16
16
const subscribe = ( listener ) => {
@@ -21,8 +21,8 @@ const createBroadcast = (initialValue) => {
21
21
}
22
22
23
23
return {
24
- getValue ,
25
- setValue ,
24
+ getState ,
25
+ setState ,
26
26
subscribe
27
27
}
28
28
}
@@ -53,19 +53,12 @@ class Broadcast extends React.Component {
53
53
54
54
broadcast = createBroadcast ( this . props . value )
55
55
56
- getBroadcastsContext ( ) {
57
- const { channel } = this . props
58
- const { broadcasts } = this . context
59
-
60
- return {
61
- ...broadcasts ,
62
- [ channel ] : this . broadcast
63
- }
64
- }
65
-
66
56
getChildContext ( ) {
67
57
return {
68
- broadcasts : this . getBroadcastsContext ( )
58
+ broadcasts : {
59
+ ...this . context . broadcasts ,
60
+ [ this . props . channel ] : this . broadcast
61
+ }
69
62
}
70
63
}
71
64
@@ -76,7 +69,7 @@ class Broadcast extends React.Component {
76
69
)
77
70
78
71
if ( this . props . value !== nextProps . value )
79
- this . broadcast . setValue ( nextProps . value )
72
+ this . broadcast . setState ( nextProps . value )
80
73
}
81
74
82
75
render ( ) {
0 commit comments