Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-subscription #12325

Merged
merged 54 commits into from
Mar 13, 2018
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d5d8bf6
POC for create-component-with-subscriptions
bvaughn Mar 5, 2018
7b1e8c2
Updated README
bvaughn Mar 5, 2018
f8743b3
Added Rollup bundle
bvaughn Mar 5, 2018
4304b55
Expanded tests
bvaughn Mar 5, 2018
30eb16a
Updated bundle comment
bvaughn Mar 5, 2018
eb1372c
Added a test for "cold" observable
bvaughn Mar 5, 2018
88e7e22
Updated inline comments
bvaughn Mar 5, 2018
c395051
Updated README examples
bvaughn Mar 5, 2018
78c9a4c
Added a test (and README docs) for Promises
bvaughn Mar 5, 2018
d1fc6e8
Added a caveat about Promises to README
bvaughn Mar 5, 2018
2e98ca9
Use a HOC for functional components and a mixin for ES6 components
bvaughn Mar 6, 2018
5093ab4
Added tests for create-react-class
bvaughn Mar 6, 2018
54468e8
Flow fix
bvaughn Mar 6, 2018
6b16b7c
Added a ref test
bvaughn Mar 6, 2018
d05ffa3
Added a test for react-lifecycles-compat
bvaughn Mar 6, 2018
bd36fb4
Updated README to show class component
bvaughn Mar 6, 2018
a11164e
Added docs for default values
bvaughn Mar 6, 2018
31edf59
Improved README examples
bvaughn Mar 6, 2018
256c5e5
Simplified Promise docs and added additional test
bvaughn Mar 6, 2018
6dcac15
Swapped functional/class component usage in examples
bvaughn Mar 6, 2018
39d7ba8
Split internal and public API tests
bvaughn Mar 6, 2018
b5571c1
Tweaks
bvaughn Mar 6, 2018
2192fd5
Changed impl to only support one subscription per component
bvaughn Mar 6, 2018
fdfa22b
Docs tweak
bvaughn Mar 6, 2018
afeb6cd
Docs tweaks
bvaughn Mar 6, 2018
7532184
Refactored create-subscription to more closely mimic context API
bvaughn Mar 7, 2018
0f936ba
Renamed create-component-with-subscriptions => create-subscription
bvaughn Mar 7, 2018
2d824c2
Renamed references to create-subscription
bvaughn Mar 7, 2018
3edff49
Replaced .toThrow with .toWarnDev
bvaughn Mar 7, 2018
e056172
Disable render-phase side effects
bvaughn Mar 7, 2018
9bdc6d6
Updated docs
bvaughn Mar 7, 2018
9ffe079
README and naming tweaks
bvaughn Mar 7, 2018
629f145
README tweaks
bvaughn Mar 7, 2018
48b4a1b
Wording tweak
bvaughn Mar 7, 2018
ee2ae93
Inline comments tweak
bvaughn Mar 7, 2018
64d80b8
Minor test tidying up
bvaughn Mar 7, 2018
ad190fb
Added more context to README intro
bvaughn Mar 7, 2018
3288726
Wordsmith nit picking
bvaughn Mar 7, 2018
81f2695
Wordsmith nit picking
bvaughn Mar 7, 2018
267a76b
Replaced Value with Value | void type
bvaughn Mar 7, 2018
db7b84f
Tweaks in response to Flarnie's feedback
bvaughn Mar 7, 2018
32d6d40
Added RxJS for tests instead of fake impls
bvaughn Mar 7, 2018
5557120
Improved children Flow type slightly
bvaughn Mar 7, 2018
ee3dfcc
Added Flow <> around config
bvaughn Mar 7, 2018
a2f43a5
Fixed example imports in README
bvaughn Mar 8, 2018
4e57ed7
Replaced createComponent() references with createSubscription() in RE…
bvaughn Mar 8, 2018
f0c68b8
Changed subscribe() to return an unsubscribe method (or false)
bvaughn Mar 8, 2018
63a65e6
Flow type tweak
bvaughn Mar 12, 2018
e6740aa
Merge branch 'master' into create-component-with-subscriptions
bvaughn Mar 13, 2018
c116528
Responded to Andrew's PR feedback
bvaughn Mar 13, 2018
c1dd9a7
Docs updatE
bvaughn Mar 13, 2018
e10e2fc
Flow tweak
bvaughn Mar 13, 2018
f03dfa9
Addressed PR feedback from Flarnie
bvaughn Mar 13, 2018
6f740d9
Removed contradictory references to Flux stores in README
bvaughn Mar 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor test tidying up
  • Loading branch information
bvaughn committed Mar 7, 2018
commit 64d80b8c86c6224a6bb057a5cffa8380387f426b
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,20 @@ describe('createSubscription', () => {
unsubscribe: (source, subscription) => subscription.unsubscribe(),
});

function render(value = 'default') {
ReactNoop.yield(value);
return null;
}

const observable = createFauxReplaySubject('initial');

ReactNoop.render(
<Subscription source={observable}>
{(value = 'default') => {
ReactNoop.yield(value);
return null;
}}
</Subscription>,
);
ReactNoop.render(<Subscription source={observable}>{render}</Subscription>);
expect(ReactNoop.flush()).toEqual(['initial']);
observable.update('updated');
expect(ReactNoop.flush()).toEqual(['updated']);

// Unsetting the subscriber prop should reset subscribed values
ReactNoop.render(
<Subscription>
{(value = 'default') => {
ReactNoop.yield(value);
return null;
}}
</Subscription>,
);
ReactNoop.render(<Subscription>{render}</Subscription>);
expect(ReactNoop.flush()).toEqual(['default']);
});

Expand All @@ -142,7 +133,7 @@ describe('createSubscription', () => {
unsubscribe: (source, subscription) => {},
});

function childrenFunction(hasLoaded) {
function render(hasLoaded) {
if (hasLoaded === undefined) {
ReactNoop.yield('loading');
} else {
Expand All @@ -160,10 +151,7 @@ describe('createSubscription', () => {
});

// Test a promise that resolves after render

ReactNoop.render(
<Subscription source={promiseA}>{childrenFunction}</Subscription>,
);
ReactNoop.render(<Subscription source={promiseA}>{render}</Subscription>);
expect(ReactNoop.flush()).toEqual(['loading']);
resolveA();
await promiseA;
Expand All @@ -173,9 +161,7 @@ describe('createSubscription', () => {
// Note that this will require an extra render anyway,
// Because there is no way to syncrhonously get a Promise's value
rejectB();
ReactNoop.render(
<Subscription source={promiseB}>{childrenFunction}</Subscription>,
);
ReactNoop.render(<Subscription source={promiseB}>{render}</Subscription>);
expect(ReactNoop.flush()).toEqual(['loading']);
await promiseB.catch(() => true);
expect(ReactNoop.flush()).toEqual(['failed']);
Expand All @@ -188,7 +174,7 @@ describe('createSubscription', () => {
unsubscribe: (source, subscription) => {},
});

function childrenFunction(value = 'default') {
function render(value = 'default') {
ReactNoop.yield(value);
return null;
}
Expand All @@ -198,14 +184,9 @@ describe('createSubscription', () => {
const promiseB = new Promise(resolve => (resolveB = resolve));

// Subscribe first to Promise A then Promsie B
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Promsie -> Promise

("Promsie" sounds like an adorable cartoon used to brainwash kids into learning JavaScript)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Promsie" 😆


ReactNoop.render(
<Subscription source={promiseA}>{childrenFunction}</Subscription>,
);
ReactNoop.render(<Subscription source={promiseA}>{render}</Subscription>);
expect(ReactNoop.flush()).toEqual(['default']);
ReactNoop.render(
<Subscription source={promiseB}>{childrenFunction}</Subscription>,
);
ReactNoop.render(<Subscription source={promiseB}>{render}</Subscription>);
expect(ReactNoop.flush()).toEqual(['default']);

// Resolve both Promises
Expand All @@ -225,7 +206,7 @@ describe('createSubscription', () => {
unsubscribe: (source, subscription) => subscription.unsubscribe(),
});

function childrenFunction(value = 'default') {
function render(value = 'default') {
ReactNoop.yield(value);
return null;
}
Expand All @@ -234,15 +215,15 @@ describe('createSubscription', () => {
const observableB = createFauxBehaviorSubject('b-0');

ReactNoop.render(
<Subscription source={observableA}>{childrenFunction}</Subscription>,
<Subscription source={observableA}>{render}</Subscription>,
);

// Updates while subscribed should re-render the child component
expect(ReactNoop.flush()).toEqual(['a-0']);

// Unsetting the subscriber prop should reset subscribed values
ReactNoop.render(
<Subscription source={observableB}>{childrenFunction}</Subscription>,
<Subscription source={observableB}>{render}</Subscription>,
);
expect(ReactNoop.flush()).toEqual(['b-0']);

Expand Down