Skip to content

Commit a84fc5c

Browse files
committed
Also update react integration to likely fix #122
1 parent 7495843 commit a84fc5c

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/integrations/preact.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,4 @@ export function connect(mapStateToProps, actions) {
6464
export function Provider(props) {
6565
this.getChildContext = () => ({ store: props.store });
6666
}
67-
// Provider.prototype.getChildContext = function () {
68-
// return { store: this.props.store };
69-
// };
7067
Provider.prototype.render = props => props.children && props.children[0] || props.children;
71-
// Provider.prototype.render = props => Array.isArray(props.children) ? props.children[0] : props.children;

src/integrations/react.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export function connect(mapStateToProps, actions) {
2525
return Child => {
2626
function Wrapper(props, context) {
2727
Component.call(this, props, context);
28-
let { store } = context;
28+
const store = context.store;
2929
let state = mapStateToProps(store ? store.getState() : {}, props);
30-
let boundActions = actions ? mapActions(actions, store) : { store };
30+
const boundActions = actions ? mapActions(actions, store) : { store };
3131
let update = () => {
32-
let mapped = mapStateToProps(store ? store.getState() : {}, this.props);
32+
let mapped = mapStateToProps(store ? store.getState() : {}, props);
3333
for (let i in mapped) if (mapped[i]!==state[i]) {
3434
state = mapped;
3535
return this.forceUpdate();
@@ -39,7 +39,10 @@ export function connect(mapStateToProps, actions) {
3939
return this.forceUpdate();
4040
}
4141
};
42-
this.componentWillReceiveProps = update;
42+
this.componentWillReceiveProps = p => {
43+
props = p;
44+
update();
45+
};
4346
this.componentDidMount = () => {
4447
store.subscribe(update);
4548
};

test/react/unistore.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe('<Provider>', () => {
240240
// await sleep(100);
241241

242242
expect(mapStateToProps).toHaveBeenCalledTimes(1);
243-
expect(mapStateToProps).toHaveBeenCalledWith({}, {});
243+
expect(mapStateToProps).toHaveBeenCalledWith({}, { a: 'b' });
244244
// outer props were changed
245245
expect(Child).toHaveBeenCalledWith(
246246
{ mappings: 2, a: 'b', store },

0 commit comments

Comments
 (0)