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

Add component type attribute so that renderqueue can choose which com… #112

Merged
merged 4 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@
"prettier",
"git add"
],
"ignore": ["./.history"]
"ignore": [
"./.history"
]
},
"bundlesize": [
{
Expand All @@ -99,7 +101,7 @@
},
{
"path": "./packages/melody-idom/lib/index.js",
"maxSize": "4.66 kB"
"maxSize": "4.67 kB"
},
{
"path": "./packages/melody-hoc/lib/index.js",
Expand All @@ -108,6 +110,10 @@
{
"path": "./packages/melody-redux/lib/index.js",
"maxSize": "1.35 kB"
},
{
"path": "./packages/melody-streams/lib/index.js",
"maxSize": "1.52 kB"
}
]
}
1 change: 1 addition & 0 deletions packages/melody-idom/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface RenderableComponent {
refs: any;
render(): void;
notify(): void;
type: String;
}

/** @type {?Node} */
Expand Down
22 changes: 12 additions & 10 deletions packages/melody-idom/src/renderQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ function addToQueue(component: RenderableComponent): void {
return;
}

// 2: Is the parent of this component already scheduled for an update?
if (getParent(component) === head.component) {
// if so: we don't need to do anything
return;
}
if (component.type !== 'streaming') {
// 2: Is the parent of this component already scheduled for an update?
if (getParent(component) === head.component) {
// if so: we don't need to do anything
return;
}

// 3: Is the component a parent of a node within the queue?
if (getParent(head.component) === component) {
// if so: replace the child with its parent
head.component = component;
return;
// 3: Is the component a parent of a node within the queue?
if (getParent(head.component) === component) {
// if so: replace the child with its parent
head.component = component;
return;
}
}

if (head.next === NIL) {
Expand Down
2 changes: 1 addition & 1 deletion packages/melody-plugin-idom/src/visitors/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Example:
This is the placeholder content that will be shown to your users while the async component is being loaded.`,
path.node.loc.start.line === path.node.loc.end.line
? path.node.loc.end.column -
path.node.loc.start.column
path.node.loc.start.column
: 'mount async'.length
);
}
Expand Down
17 changes: 16 additions & 1 deletion packages/melody-streams/__tests__/componentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
applyAsGroupAndComplete,
} from './util/testHelpers';
import { last, first } from 'rxjs/operators';
import { Observable, ReplaySubject } from 'rxjs';
import { Observable, ReplaySubject, concat, throwError, of } from 'rxjs';

const template = {
render(_context) {
Expand Down Expand Up @@ -198,6 +198,21 @@ describe('component', () => {
/* eslint-enable no-console */
})
);
it('should pass through an error message for non-production environments', () => {
const root = document.createElement('div');
const error = new Error('oops!');
const MyComponent = createComponent(
() => concat(of(7), throwError(error)),
template
);
/* eslint-disable no-console */
const temp = console.error;
console.error = jest.fn();
render(root, MyComponent);
expect(console.error).toHaveBeenCalledWith('Error: ', error);
console.error = temp;
/* eslint-enable no-console */
});
it(
'should not emit a warning message after if component emits state before 500ms if not state updates',
fakeSchedulers(advance => {
Expand Down
34 changes: 15 additions & 19 deletions packages/melody-streams/src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function Component(element) {
}

Object.assign(Component.prototype, {
type: 'streaming',
apply(props) {
this.propsStream.next(props);
if (this.subscriptions.length === 0) {
Expand All @@ -67,26 +68,21 @@ Object.assign(Component.prototype, {
subscribe: obs => this.subscriptions.push(obs.subscribe()),
});
const warningSubscription = warningTimer.subscribe();
const s = t
.pipe(
distinctUntilChanged(shallowEqual),
catchError(err => of(err))
)
.subscribe(
state => {
if (!warningSubscription.closed)
warningSubscription.unsubscribe();
this.state = state;
enqueueComponent(this);
},
err => {
if (process.env.NODE_ENV !== 'production') {
/* eslint-disable no-console */
console.error('Error: ', err);
/* eslint-enable no-console */
}
const s = t.pipe(distinctUntilChanged(shallowEqual)).subscribe(
state => {
if (!warningSubscription.closed)
warningSubscription.unsubscribe();
this.state = state;
enqueueComponent(this);
},
err => {
if (process.env.NODE_ENV !== 'production') {
/* eslint-disable no-console */
console.error('Error: ', err);
/* eslint-enable no-console */
}
);
}
);

this.subscriptions.push(s);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/melody-streams/src/operators/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { isObservable } from 'rxjs';

export const combine = (...streams) =>
mergeIntoObject(
...streams.map(
stream => (isObservable(stream) ? stream : mergeObject(stream))
...streams.map(stream =>
isObservable(stream) ? stream : mergeObject(stream)
)
);
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5113,7 +5113,7 @@ micromatch@^3.1.10, micromatch@^3.1.4:
snapdragon "^0.8.1"
to-regex "^3.0.2"

"micromatch@github:jonschlinkert/micromatch#2.2.0":
micromatch@jonschlinkert/micromatch#2.2.0:
version "2.2.0"
resolved "https://codeload.github.com/jonschlinkert/micromatch/tar.gz/5017fd78202e04c684cc31d3c2fb1f469ea222ff"
dependencies:
Expand Down