Skip to content

Commit

Permalink
cleanup references to global dispatch from old API
Browse files Browse the repository at this point in the history
  • Loading branch information
ShMcK committed Jul 13, 2018
1 parent f210d9b commit 6c2c446
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
4 changes: 0 additions & 4 deletions docs/api.md
@@ -1,9 +1,5 @@
# @rematch/core API

```js
import { init, dispatch, getState } from '@rematch/core'
```

- [init](#init)
- [models](#models)
- [state](#state)
Expand Down
8 changes: 4 additions & 4 deletions docs/recipes/testing.md
Expand Up @@ -6,7 +6,7 @@
Testing with store.

```jsx
import { init, dispatch } from "@rematch/core";
import { init } from "@rematch/core";
import myModel from './myModel';

describe("myModel model", () => {
Expand All @@ -15,7 +15,7 @@ Testing with store.
models: { myModel }
});

dispatch.myModel.reducerName(payload);
store.dispatch.myModel.reducerName(payload);

const myModelData = store.getState().myModel;
expect(myModelData).toBe("something");
Expand All @@ -42,7 +42,7 @@ Testing reducers directly.
Testing with store.

```jsx
import { init, dispatch } from "@rematch/core";
import { init } from "@rematch/core";
import myModel from './myModel';

describe("myModel model", () => {
Expand All @@ -51,7 +51,7 @@ Testing with store.
models: { myModel }
});

await dispatch.myModel.effectName(payload);
await store.dispatch.myModel.effectName(payload);

const myModelData = store.getState().myModel;
expect(myModelData).toBe("something");
Expand Down
16 changes: 6 additions & 10 deletions plugins/react-navigation/README.md
Expand Up @@ -44,7 +44,7 @@ export default StackNavigator(

```js
// index.js
import { init, dispatch } from '@rematch/core'
import { init } from '@rematch/core'
import createReactNavigationPlugin from '@rematch/react-navigation'
import * as ReactNavigation from 'react-navigation'
import Routes from './Routes'
Expand Down Expand Up @@ -79,19 +79,15 @@ dispatch.nav.setParams = (action) => dispatch(NavigationActions.setParams(action
Just pass the NavigationAction options.

```js
// somewhere in your app
import { dispatch } from '@rematch/core'

dispatch.nav.navigate({ routeName: 'Login' })
store.dispatch.nav.navigate({ routeName: 'Login' })
```

If necessary, import `NavigationActions`.

```js
import { dispatch } from '@rematch/core'
import { NavigationActions } from 'react-navigation'

const resetAction = dispatch.navigate.reset({
const resetAction = store.dispatch.navigate.reset({
index: 1,
actions: [
NavigationActions.navigate({ routeName: 'Profile'}),
Expand All @@ -105,7 +101,7 @@ const resetAction = dispatch.navigate.reset({
An example for setting up the Android back button handling with react-navigation.

```js
import { dispatch, init } from '@rematch/core'
import { init } from '@rematch/core'
import createReactNavigation from '@rematch/react-navigation'
import React from 'react'
import { BackHandler } from 'react-native'
Expand All @@ -125,7 +121,7 @@ export class App extends React.Component {
if (store.getState().nav.index === 0) {
BackHandler.exitApp()
}
dispatch.nav.back()
store.dispatch.nav.back()
return true
}

Expand Down Expand Up @@ -190,7 +186,7 @@ to `createReactNavigationPlugin`. Here is a minimal example:

```js
// index.js
import { init, dispatch } from '@rematch/core'
import { init } from '@rematch/core'
import createReactNavigationPlugin from '@rematch/react-navigation'
import * as ReactNavigation from 'react-navigation'
import Routes from './Routes'
Expand Down
4 changes: 2 additions & 2 deletions plugins/updated/examples/count/src/models.js
Expand Up @@ -5,12 +5,12 @@ export const count = {
reducers: {
increment: s => s + 1
},
effects: {
effects: dispatch => ({
asyncIncrement: async () => {
await new Promise((resolve) => {
setTimeout(resolve, 1000)
})
dispatch.count.increment()
}
},
}),
}

0 comments on commit 6c2c446

Please sign in to comment.