Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Fix tree shaking (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
ganemone authored Jan 29, 2018
1 parent ec8a325 commit f3bd9c4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 49 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
},
"devDependencies": {
"babel-eslint": "8.2.1",
"create-universal-package": "3.2.6",
"create-universal-package": "3.3.0",
"eslint": "4.16.0",
"eslint-config-fusion": "0.2.1",
"eslint-plugin-cup": "1.0.0",
"eslint-plugin-flowtype": "2.42.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-prettier": "2.5.0",
"eslint-plugin-react": "7.6.0",
"flow-bin": "0.64.0",
"fusion-core": "0.3.0-4",
"fusion-test-utils": "0.4.1",
"fusion-test-utils": "0.4.2",
"fusion-tokens": "0.0.5",
"nyc": "11.4.1",
"prettier": "1.10.2",
Expand Down
14 changes: 8 additions & 6 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ class UniversalEmitter extends Emitter {
}
}

const plugin = createPlugin({
deps: {fetch: FetchToken},
provides: ({fetch}) => {
return new UniversalEmitter(fetch);
},
});
const plugin =
__BROWSER__ &&
createPlugin({
deps: {fetch: FetchToken},
provides: ({fetch}) => {
return new UniversalEmitter(fetch);
},
});

export default plugin;
55 changes: 28 additions & 27 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,33 @@ class ScopedEmitter extends Emitter {
teardown() {}
}

export default createPlugin({
provides: () => new GlobalEmitter(),
middleware: (deps, globalEmitter) => {
const bodyParser = require('koa-bodyparser');
const parseBody = bodyParser();
return async function universalEventsMiddleware(ctx, next) {
const emitter = globalEmitter.from(ctx);
if (ctx.method === 'POST' && ctx.path === '/_events') {
await parseBody(ctx, async () => {});
const {items} = ctx.request.body;
if (items) {
for (let index = 0; index < items.length; index++) {
const {type, payload} = items[index];
emitter.emit(type, payload);
export default __NODE__ &&
createPlugin({
provides: () => new GlobalEmitter(),
middleware: (deps, globalEmitter) => {
const bodyParser = require('koa-bodyparser');
const parseBody = bodyParser();
return async function universalEventsMiddleware(ctx, next) {
const emitter = globalEmitter.from(ctx);
if (ctx.method === 'POST' && ctx.path === '/_events') {
await parseBody(ctx, async () => {});
const {items} = ctx.request.body;
if (items) {
for (let index = 0; index < items.length; index++) {
const {type, payload} = items[index];
emitter.emit(type, payload);
}
ctx.status = 200;
} else {
ctx.status = 400;
}
ctx.status = 200;
} else {
ctx.status = 400;
}
}
// awaiting next before registering `then` on ctx.timing.end to try and get as much as possible
// into the event batch flush.
await next();
ctx.timing.end.then(() => {
emitter.flush();
});
};
},
});
// awaiting next before registering `then` on ctx.timing.end to try and get as much as possible
// into the event batch flush.
await next();
ctx.timing.end.then(() => {
emitter.flush();
});
};
},
});
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.3.29.tgz#7f2ad7ec55f914482fc9b1ec4bb1ae6028d46066"

"@types/node@^9.3.0":
version "9.3.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.3.0.tgz#3a129cda7c4e5df2409702626892cb4b96546dd5"
version "9.4.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.0.tgz#b85a0bcf1e1cc84eb4901b7e96966aedc6f078d1"

"@types/rimraf@^0.0.28":
version "0.0.28"
Expand Down Expand Up @@ -1456,9 +1456,9 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

create-universal-package@3.2.6:
version "3.2.6"
resolved "https://registry.yarnpkg.com/create-universal-package/-/create-universal-package-3.2.6.tgz#8269a7ac8ad5d1e13139a36f18d139fb48000483"
create-universal-package@3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/create-universal-package/-/create-universal-package-3.3.0.tgz#69c31d117705f72b8c418c1140e4cf051160ef9d"
dependencies:
"@babel/core" "^7.0.0-beta.36"
"@babel/plugin-transform-flow-strip-types" "^7.0.0-beta.36"
Expand Down Expand Up @@ -1654,8 +1654,8 @@ doctrine@^2.0.2, doctrine@^2.1.0:
esutils "^2.0.2"

domain-browser@^1.1.1:
version "1.1.7"
resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc"
version "1.2.0"
resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.2.0.tgz#3d31f50191a6749dd1375a7f522e823d42e54eda"

draftlog@^1.0.12:
version "1.0.12"
Expand Down Expand Up @@ -1870,7 +1870,7 @@ eslint-plugin-flowtype@2.42.0:
dependencies:
lodash "^4.15.0"

eslint-plugin-import@2.8.0:
eslint-plugin-import@^2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.8.0.tgz#fa1b6ef31fcb3c501c09859c1b86f1fc5b986894"
dependencies:
Expand Down Expand Up @@ -2258,9 +2258,9 @@ fusion-core@0.3.0-4:
node-mocks-http "^1.6.6"
toposort "^1.0.6"

fusion-test-utils@0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/fusion-test-utils/-/fusion-test-utils-0.4.1.tgz#c834945eb0bdecc6f56993c4daaf4f4e13416029"
fusion-test-utils@0.4.2:
version "0.4.2"
resolved "https://registry.yarnpkg.com/fusion-test-utils/-/fusion-test-utils-0.4.2.tgz#a8cc45eea3c6943cb41ba4b61f699adb126ef531"
dependencies:
assert "^1.4.1"
koa "^2.4.1"
Expand Down Expand Up @@ -3343,8 +3343,8 @@ node-pre-gyp@^0.6.39:
tar-pack "^3.4.0"

nodent-compiler@>=3.1.0:
version "3.1.6"
resolved "https://registry.yarnpkg.com/nodent-compiler/-/nodent-compiler-3.1.6.tgz#1fd2b37625f127405d90ddc9cf7a059affef82f5"
version "3.1.7"
resolved "https://registry.yarnpkg.com/nodent-compiler/-/nodent-compiler-3.1.7.tgz#78198d9baacc491b0065b8c65bc0ca83d3fcd2a2"
dependencies:
acorn ">=2.5.2"
acorn-es7-plugin ">=1.1.6"
Expand Down

0 comments on commit f3bd9c4

Please sign in to comment.