to access the same state but do not have any parent/child relationship • you start to feel awkward passing down the state to multiple components with props Dan Abramov says “Flux libraries are like glasses: you’ll know when you need them.”
A reducer is just a pure function. A reducer takes two parameters: the current state and an action const rootReducer = (state = initialState, action) => state;
Client 2.0. InMemoryCache is a normalized data store that supports all of Apollo Client 1.0’s features without the dependency on Redux. import { InMemoryCache } from 'apollo-cache-inmemory'; import { HttpLink } from 'apollo-link-http'; import ApolloClient from 'apollo-client'; const cache = new InMemoryCache(); const client = new ApolloClient({ link: new HttpLink(), cache }); In some instances, you may need to manipulate the cache directly, such as updating the store after a mutation.
properties to customize your cache: • addTypename: A boolean to determine whether to add __typename to the document (default: true) • dataIdFromObject: A function that takes a data object and returns a unique identifier to be used when normalizing the data in the store. • fragmentMatcher: By default, the InMemoryCache uses a heuristic fragment matcher. If you are using fragments on unions and interfaces, you will need to use an IntrospectionFragmentMatcher. • cacheRedirects (previously known as cacheResolvers or customResolvers): A map of functions to redirect a query to another entry in the cache before a request takes place. This is useful if you have a list of items and want to use the data from the list query on a detail page where you’re querying an individual item.
keys of id and _id for the unique identifier if they exist along with __typename on an object If id and _id are not specified, or if __typename is not specified, InMemoryCache will fall back to the path to the object in the query, such as ROOT_QUERY.allPeople.0 const cache = new InMemoryCache({ dataIdFromObject: object => object.key || null });
gql` query ReadTodo { todo(id: 5) { id text completed } } `, }); To interact directly with your cache, you can use the Apollo Client class methods readQuery, readFragment, writeQuery, and writeFragment.
NgrxCacheModule, ], }) class AppModule { constructor(ngrxCache: NgrxCache) { const cache = ngrxCache.create({}); } } Put apolloReducer under apollo in your State and import NgrxCacheModule