Skip to content

Commit 79576e6

Browse files
committed
Tweak some var names
1 parent f223d41 commit 79576e6

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

modules/Broadcast.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@ import React from "react"
22
import PropTypes from "prop-types"
33
import invariant from "invariant"
44

5-
function createBroadcast(initialState) {
6-
let listeners = []
7-
let currentState = initialState
5+
function createBroadcast(initialValue) {
6+
let currentValue = initialValue
7+
let subscribers = []
88

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

11-
const setState = state => {
12-
currentState = state
13-
listeners.forEach(listener => listener(currentState))
11+
const publish = state => {
12+
currentValue = state
13+
subscribers.forEach(s => s(currentValue))
1414
}
1515

16-
const subscribe = listener => {
17-
listeners.push(listener)
16+
const subscribe = subscriber => {
17+
subscribers.push(subscriber)
1818

19-
return () => (listeners = listeners.filter(item => item !== listener))
19+
return () => {
20+
subscribers = subscribers.filter(s => s !== subscriber)
21+
}
2022
}
2123

2224
return {
23-
getState,
24-
setState,
25+
getValue,
26+
publish,
2527
subscribe
2628
}
2729
}
@@ -70,7 +72,7 @@ class Broadcast extends React.Component {
7072
invariant(this.props.channel === nextProps.channel, "You cannot change <Broadcast channel>")
7173

7274
if (!this.props.compareValues(this.props.value, nextProps.value)) {
73-
this.broadcast.setState(nextProps.value)
75+
this.broadcast.publish(nextProps.value)
7476
}
7577
}
7678

modules/Subscriber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Subscriber extends React.Component {
4444

4545
if (broadcast) {
4646
this.setState({
47-
value: broadcast.getState()
47+
value: broadcast.getValue()
4848
})
4949
}
5050
}

0 commit comments

Comments
 (0)