Skip to content

Commit eb95935

Browse files
committed
s/value/state/g
1 parent 5a2352c commit eb95935

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

modules/Broadcast.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import invariant from 'invariant'
22
import React, { PropTypes } from 'react'
33

4-
const createBroadcast = (initialValue) => {
4+
const createBroadcast = (initialState) => {
55
let listeners = []
6-
let currentValue = initialValue
6+
let currentState = initialState
77

8-
const getValue = () =>
9-
currentValue
8+
const getState = () =>
9+
currentState
1010

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))
1414
}
1515

1616
const subscribe = (listener) => {
@@ -21,8 +21,8 @@ const createBroadcast = (initialValue) => {
2121
}
2222

2323
return {
24-
getValue,
25-
setValue,
24+
getState,
25+
setState,
2626
subscribe
2727
}
2828
}
@@ -53,19 +53,12 @@ class Broadcast extends React.Component {
5353

5454
broadcast = createBroadcast(this.props.value)
5555

56-
getBroadcastsContext() {
57-
const { channel } = this.props
58-
const { broadcasts } = this.context
59-
60-
return {
61-
...broadcasts,
62-
[channel]: this.broadcast
63-
}
64-
}
65-
6656
getChildContext() {
6757
return {
68-
broadcasts: this.getBroadcastsContext()
58+
broadcasts: {
59+
...this.context.broadcasts,
60+
[this.props.channel]: this.broadcast
61+
}
6962
}
7063
}
7164

@@ -76,7 +69,7 @@ class Broadcast extends React.Component {
7669
)
7770

7871
if (this.props.value !== nextProps.value)
79-
this.broadcast.setValue(nextProps.value)
72+
this.broadcast.setState(nextProps.value)
8073
}
8174

8275
render() {

modules/Subscriber.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ class Subscriber extends React.Component {
2020
}
2121

2222
getBroadcast() {
23-
return this.context.broadcasts[this.props.channel]
24-
}
25-
26-
componentWillMount() {
27-
const broadcast = this.getBroadcast()
23+
const broadcast = this.context.broadcasts[this.props.channel]
2824

2925
invariant(
3026
broadcast,
@@ -33,8 +29,14 @@ class Subscriber extends React.Component {
3329
this.props.channel
3430
)
3531

32+
return broadcast
33+
}
34+
35+
componentWillMount() {
36+
const broadcast = this.getBroadcast()
37+
3638
this.setState({
37-
value: broadcast.getValue()
39+
value: broadcast.getState()
3840
})
3941
}
4042

0 commit comments

Comments
 (0)