Skip to content

Commit

Permalink
fixup! feat(react): add connect React HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Laundal committed Apr 2, 2020
1 parent 0078b52 commit be5156f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/react/connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,27 @@ test('connect should forward props', async (t) => {
});

t.deepEqual(WrappedComponentSpy.firstCall?.args[0], {
...additionalProps,
...initialProps,
});
});

test('connect give streamed props precedence over forwarded props', (t) => {
const { WrappedComponentSpy } = t.context;
const HOComponent = connect(WrappedComponentSpy, of(initialProps));

act(() => {
create(
React.createElement(HOComponent, {
...additionalProps,
msg: 'overriding should not work',
})
);
});

t.deepEqual(WrappedComponentSpy.firstCall?.args[0], {
...additionalProps,
...initialProps,
});
});

Expand All @@ -112,11 +131,11 @@ test('connect should propagate changes to forwarded props', async (t) => {
});

t.deepEqual(WrappedComponentSpy.firstCall?.args[0], {
...initialProps,
...additionalProps,
...initialProps,
});
t.deepEqual(WrappedComponentSpy.secondCall?.args[0], {
...initialProps,
...secondAdditionalProps,
...initialProps,
});
});
5 changes: 5 additions & 0 deletions src/react/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import React, { ComponentType } from 'react';
* any missing properties will be required by the component returned from this
* component.
*
* Typescript does, in certain cases, allow for extra properties to be unpacked
* on a component. This means it may be possible to send props which would be
* provided by the stream. In these cases the values from the stream will
* override any values passed as props.
*
* @param WrappedComponent Component that will recieve props from the stream
* @param stream$ Stream that will provide props to the component
* @see useStream
Expand Down

0 comments on commit be5156f

Please sign in to comment.