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

Commit

Permalink
improving docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonnymichel committed Feb 9, 2020
1 parent 1b0b7df commit 29a6b21
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,42 +179,41 @@ Steps to reproduce:
Check out the [Codesandbox demo!](https://codesandbox.io/s/r58pqonkop)

## Methods API
### <a name="api_createStore">`createStore`</a>
`createStore(name:String, state?:any, reducer?:(state:any, data:any) -> any) -> StoreInterface`
### <a name="api_createStore">`createStore(name: String, state?: any, reducer?: (state:any, data:any) -> any) -> StoreInterface`</a>
Creates a store to be used across the entire application. Returns a StoreInterface object.
### Arguments
#### `name:String`
#### `name: String`
The namespace for your store, it can be used to identify the store across the application.
#### `state:any = {}`
#### `state: any = {}`
The store's initial state. it can be any data type. defaults to an empty object. Optional
#### `reducer:(state:any, data:any) -> any`
#### `reducer: (state:any, data:any) -> any`
You can specify a reducer function to take care of state changes. the reducer functions receives two arguments, the previous state and the data dispatched. the function must return a new state, if not, the new state will be `null`. Optional

### <a name="api_getStoreByName">`getStoreByName(name:String) -> StoreInterface`</a>
### <a name="api_getStoreByName">`getStoreByName(name: String) -> StoreInterface`</a>
Finds a store by its name and returns its instance.
### Arguments
#### `name:String`
#### `name: String`
The name of the store.

## Objects API
### <a name="api_storeInterface">`StoreInterface`</a>
The store instance that is returned by the createStore and getStoreByName methods.
### Interface
#### `name:String`
#### `name: String`
The name of the store;
#### `getState:() -> state`
#### `getState: () -> state`
A method that returns the store's current state
#### `setState:(state:any, callback?:(state:any) -> void)`
#### `setState: (state: any, callback?: (state:any) -> void)`
Sets the state of the store. works if the store does not use a reducer state handler. Otherwise, use `dispatch`. callback is optional and will be invoked once the state is updated, receiving the updated state as argument.
#### `dispatch(data:any, callback?(state:any) -> void)`
#### `dispatch(data: any, callback?: (state: any) -> void)`
Dispatches data to update the state. works if the store uses a reducer state handler. Otherwise, use `setState`. callback is optional and will be invoked once the state is updated, receiving the updated state as argument.
#### `subscribe(callback(state) | callback(state, data)) -> unsubscribe:() -> void`
#### `subscribe(callback: (state) -> void | callback: (state, data) -> void) -> unsubscribe: () -> void`
The callback function will be invoked everytime the store state changes. If the store is reducer-based, the callback function will be called with the state and the dispatched data as arguments. otherwise, it'll be called with state as the only argument.

the subscribe method returns a function that can be called in order to cancel the subscription for the callback function.

## React API
### <a name="api_useStore">`useStore(identifier:String|StoreInterface) -> [state, setState|dispatch]`</a>
### <a name="api_useStore">`useStore(identifier: String|StoreInterface) -> [state, setState|dispatch]`</a>
A function that returns a pair with the current state and a function to trigger state updates for the specified store.
### Arguments
#### Identifier:String|StoreInterface
Expand Down

0 comments on commit 29a6b21

Please sign in to comment.