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

Commit

Permalink
Add immutable support (#137)
Browse files Browse the repository at this point in the history
* ensure it works with redux-loop

* support immutable store

* bump changelog
  • Loading branch information
James Baxley authored Aug 13, 2016
1 parent 45a2df3 commit 58eb6d1
Show file tree
Hide file tree
Showing 12 changed files with 2,977 additions and 131 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Expect active development and potentially significant breaking changes in the `0.x` track. We'll try to be diligent about releasing a `1.0` version in a timely fashion (ideally within 1 or 2 months), so that we can take advantage of SemVer to signify breaking changes from that point on.

### v4.0.3

- Feature: Support a different store in the tree that is immutable (support immutable redux) [#137](https://github.com/apollostack/react-apollo/pull/137)

### v4.0.2

- Bug: Fixed refetch methods when no result is returned
Expand Down
5 changes: 5 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ declare module 'lodash.flatten' {
import main = require('lodash');
export = main.flatten;
}

declare module 'redux-loop' {
function combineReducers(reducers: any, state?: any, get?: any, set?: any): any;
function install(): any;
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-apollo",
"version": "0.4.2",
"version": "0.4.3",
"description": "React data container for Apollo Client",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -64,6 +64,7 @@
"graphql": "^0.5.0",
"graphql-tag": "^0.1.7",
"gzip-size": "^3.0.0",
"immutable": "^3.8.1",
"isomorphic-fetch": "^2.2.1",
"istanbul": "^0.4.2",
"jest": "^14.1.0",
Expand All @@ -82,6 +83,8 @@
"react-test-renderer": "^15.3.0",
"redux": "^3.5.2",
"redux-form": "^5.3.2",
"redux-immutable": "^3.0.7",
"redux-loop": "^2.2.2",
"remap-istanbul": "^0.5.1",
"source-map-support": "^0.4.0",
"swapi-graphql": "0.0.4",
Expand Down
4 changes: 4 additions & 0 deletions src/ApolloProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import invariant = require('invariant');

export declare interface ProviderProps {
store?: Store<any>;
immutable?: boolean;
client: ApolloClient;
}

Expand All @@ -27,6 +28,7 @@ export default class ApolloProvider extends Component<ProviderProps, any> {
getState: PropTypes.func.isRequired,
}),
client: PropTypes.object.isRequired,
immutable: PropTypes.bool,
children: PropTypes.element.isRequired,
};

Expand All @@ -51,6 +53,8 @@ export default class ApolloProvider extends Component<ProviderProps, any> {

if (props.store) {
this.store = props.store;
// support an immutable store alongside apollo store
if (props.immutable) props.client.initStore();
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import assign = require('object-assign');

import hoistNonReactStatics = require('hoist-non-react-statics');

import {
Store,
} from 'redux';

import ApolloClient, {
readQueryFromStore,
} from 'apollo-client';
Expand Down Expand Up @@ -48,6 +44,10 @@ import {
Subscription,
} from 'apollo-client/util/Observable';

import {
ApolloStore,
} from 'apollo-client/store';

import {
// GraphQLResult,
Document,
Expand Down Expand Up @@ -229,7 +229,7 @@ export default function graphql(
public hasMounted: boolean;

// data storage
private store: Store<any>;
private store: ApolloStore;
private client: ApolloClient; // apollo client
private data: any = {}; // apollo data
private type: DocumentType;
Expand All @@ -251,8 +251,8 @@ export default function graphql(
constructor(props, context) {
super(props, context);
this.version = version;
this.store = props.store || context.store;
this.client = props.client || context.client;
this.store = this.client.store;

invariant(!!this.client,
`Could not find "client" in either the context or ` +
Expand Down
Loading

0 comments on commit 58eb6d1

Please sign in to comment.