Skip to content

Commit

Permalink
Merge pull request #7 from transceptor-technology/children
Browse files Browse the repository at this point in the history
fix withVlow children bug
  • Loading branch information
Jeroen van der Heijden authored Feb 8, 2021
2 parents 96d3779 + d055fb0 commit a30191a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/withVlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var withVlow = function withVlow(stores, WrappedComponent) {
(0, _createClass2["default"])(WithVlow, [{
key: "render",
value: function render() {
return _react["default"].createElement(WrappedComponent, (0, _extends2["default"])({}, this.state, this.props), null);
return _react["default"].createElement(WrappedComponent, (0, _extends2["default"])({}, this.state, this.props), this.props ? this.props.children : null);
}
}]);
return WithVlow;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vlow",
"version": "1.1.10",
"version": "1.1.11",
"description": "A simple library for unidirectional dataflow architecture inspired by Reflux",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/withVlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const withVlow = (stores, WrappedComponent) => {
Array.isArray(stores) ? this.mapStores(stores) : this.mapStore(stores);
}
render() {
return React.createElement(WrappedComponent, Object.assign({}, this.state, this.props), null);
return React.createElement(WrappedComponent, Object.assign({}, this.state, this.props), this.props ? this.props.children : null);
}
};
WithVlow.displayName = `WithVlow()(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
Expand Down
36 changes: 17 additions & 19 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class TestComponent extends Vlow.Component {
}
}

const TestWithComponent = withVlow(TestStore)(() => null);

class SomeClass extends React.Component {
isSomeClass() {
return true;
Expand All @@ -58,6 +56,8 @@ class SomeClass extends React.Component {
}
}

const TestWithComponent = withVlow(TestStore)(SomeClass);

class TestExtendedComponent extends Vlow.Component.extend(SomeClass) {
constructor(props) {
super(props);
Expand Down Expand Up @@ -89,30 +89,29 @@ describe('Test Vlow.createActions', () => {
it('Create valid actions', () => {
let result;
assert.doesNotThrow(() => { result = Vlow.createActions(['fetch', 'update']); });
assert.equal(typeof result.fetch, 'function');
assert.equal(typeof result.update, 'function');
assert.strictEqual(typeof result.fetch, 'function');
assert.strictEqual(typeof result.update, 'function');
});

});

describe('Test Vlow.Component', () => {
const component = new TestComponent();

it('Initial items should return empty', () => {
assert.deepEqual(component.state.items, []);
assert.deepStrictEqual(component.state.items, []);
});

it('Add action should add items to the store', () => {
TestActions.add(item0);
TestActions.add(item1);
assert.equal(component.state.items.length, 2);
assert.strictEqual(component.state.items.length, 2);
});

it('Pop action should remove the last item from the store', () => {
assert.equal(component.state.items.length, 2);
assert.strictEqual(component.state.items.length, 2);
TestActions.pop();
TestActions.pop();
assert.equal(component.state.items.length, 0);
assert.strictEqual(component.state.items.length, 0);
});

it('Component should be able to mount', () => {
Expand All @@ -129,27 +128,26 @@ describe('Test withVlow', () => {
const component = new TestWithComponent();

it('Initial items should return empty', () => {
assert.deepEqual(component.state.items, []);
assert.deepStrictEqual(component.state.items, []);
});

it('Add action should add items to the store', () => {
TestActions.add(item0);
TestActions.add(item1);
assert.equal(component.state.items.length, 2);
assert.strictEqual(component.state.items.length, 2);
});

it('Pop action should remove the last item from the store', () => {
assert.equal(component.state.items.length, 2);
assert.strictEqual(component.state.items.length, 2);
TestActions.pop();
TestActions.pop();
assert.equal(component.state.items.length, 0);
assert.strictEqual(component.state.items.length, 0);
});

it('Component should be able to mount', () => {
assert.doesNotThrow(() => { component.componentDidMount(); });
});


it('Component should unmount', () => {
assert.doesNotThrow(() => { component.componentWillUnmount(); });
});
Expand All @@ -159,20 +157,20 @@ describe('Test Vlow.Component.extend', () => {
const extendedComponent = new TestExtendedComponent();

it('Initial items should return empty', () => {
assert.deepEqual(extendedComponent.state.items, []);
assert.deepStrictEqual(extendedComponent.state.items, []);
});

it('Add action should add items to the store', () => {
TestActions.add(item0);
TestActions.add(item1);
assert.equal(extendedComponent.state.items.length, 2);
assert.strictEqual(extendedComponent.state.items.length, 2);
});

it('Pop action should remove the last item from the store', () => {
assert.equal(extendedComponent.state.items.length, 2);
assert.strictEqual(extendedComponent.state.items.length, 2);
TestActions.pop();
TestActions.pop();
assert.equal(extendedComponent.state.items.length, 0);
assert.strictEqual(extendedComponent.state.items.length, 0);
});

it('Component should be able to mount', () => {
Expand Down Expand Up @@ -228,7 +226,7 @@ describe('Test alter state', () => {

it('Component len state property should be set', () => {
TestActions.add(item0);
assert.equal(component.state.len, 1);
assert.strictEqual(component.state.len, 1);
});

it('Component should unmount and persistent stores should be checked', () => {
Expand Down

0 comments on commit a30191a

Please sign in to comment.