Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Bundle reductions inspired by examples/rollup app. #2842

Merged
merged 3 commits into from
Mar 5, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"bundlesize": [
{
"path": "./dist/bundlesize.js",
"maxSize": "6.4 KB"
"maxSize": "5.2 KB"
}
],
"jest": {
Expand Down
32 changes: 25 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@ function onwarn(message) {
}
}

const globals = {
'apollo-client': 'apollo.core',
'hoist-non-react-statics': 'hoistNonReactStatics',
'prop-types': 'propTypes',
'react': 'react',
'ts-invariant': 'invariant',
'tslib': 'tslib',
};

function external(id) {
return Object.prototype.hasOwnProperty.call(globals, id);
}

export default [
{
input: 'src/index.ts',
output: {
file: 'lib/react-apollo.esm.js',
format: 'esm',
sourcemap: true,
globals,
},
external,
plugins: [
node({
module: true,
only: ['tslib']
}),
node({ module: true }),
typescriptPlugin({ typescript }),
invariantPlugin(),
filesize(),
Expand All @@ -37,26 +49,32 @@ export default [
output: {
file: 'lib/react-apollo.cjs.js',
format: 'cjs',
name: 'react-apollo'
name: 'react-apollo',
globals,
},
external,
onwarn,
},
{
input: 'lib/react-apollo.esm.js',
output: {
file: 'lib/react-apollo.umd.js',
format: 'umd',
name: 'react-apollo'
name: 'react-apollo',
globals,
},
external,
onwarn,
},
{
input: 'lib/react-apollo.esm.js',
output: {
file: 'dist/bundlesize.js',
format: 'cjs',
name: 'react-apollo'
name: 'react-apollo',
globals,
},
external,
plugins: [
uglify({
mangle: {
Expand Down
48 changes: 11 additions & 37 deletions src/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,8 @@ export type ObservableQueryFields<TData, TVariables> = Pick<
) => Promise<ApolloQueryResult<TData2>>);
};

function compact(obj: any) {
return Object.keys(obj).reduce(
(acc, key) => {
if (obj[key] !== undefined) {
acc[key] = obj[key];
}

return acc;
},
{} as any,
);
}

function observableQueryFields<TData, TVariables>(
observable: ObservableQuery<TData>,
observable: ObservableQuery<TData, TVariables>,
): ObservableQueryFields<TData, TVariables> {
const fields = {
variables: observable.variables,
Expand Down Expand Up @@ -124,7 +111,7 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
// request / action storage. Note that we delete querySubscription if we
// unsubscribe but never delete queryObservable once it is created. We
// only delete queryObservable when we unmount the component.
private queryObservable?: ObservableQuery<TData> | null;
private queryObservable?: ObservableQuery<TData, TVariables> | null;
private querySubscription?: ZenObservable.Subscription;
private previousData: any = {};
private refetcherQueue?: {
Expand Down Expand Up @@ -253,18 +240,7 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
}

private extractOptsFromProps(props: QueryProps<TData, TVariables>) {
const {
variables,
pollInterval,
fetchPolicy,
errorPolicy,
notifyOnNetworkStatusChange,
query,
displayName = 'Query',
context = {},
} = props;

this.operation = parser(query);
this.operation = parser(props.query);

invariant(
this.operation.type === DocumentType.Query,
Expand All @@ -273,16 +249,14 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
}.`,
);

return compact({
variables,
pollInterval,
query,
fetchPolicy,
errorPolicy,
notifyOnNetworkStatusChange,
metadata: { reactComponent: { displayName } },
context,
});
const displayName = props.displayName || 'Query';

return {
...props,
displayName,
context: props.context || {},
metadata: { reactComponent: { displayName }},
};
}

private initializeQueryObservable(props: QueryProps<TData, TVariables>) {
Expand Down