Skip to content

Commit

Permalink
Add setup method
Browse files Browse the repository at this point in the history
  • Loading branch information
nhunzaker committed Aug 15, 2016
1 parent d61bc0a commit cf9adf1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
13 changes: 13 additions & 0 deletions docs/api/microcosm.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ as [React](https://facebook.github.io/react/)).

## API

### `setup()`

Called whenever a Microcosm is instantiated. This provides a general
purpose hook for adding stores and other setup behavior.

```javscript
class SolarSystem extends Microcosm {
setup() {
this.addStore('planets', Planets)
}
}
```

### `getInitialState()`

Generates the starting state for a Microcosm instance. This is the
Expand Down
4 changes: 1 addition & 3 deletions examples/react-router/app/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import Lists from './stores/lists'

export default class Todos extends Microcosm {

constructor(options) {
super(options)

setup() {
// 1. Lists
this.addStore('lists', Lists)

Expand Down
12 changes: 12 additions & 0 deletions src/microcosm.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ export default class Microcosm extends Emitter {

// Standard store reduction behaviors
this.addStore(MetaStore)

// Microcosm is now ready. Call the initialize method
this.setup()
}

/**
* Called whenever a Microcosm is instantiated. This provides a
* more intentional preparation phase that does not require
* tapping into the constructor
*/
setup() {
// NOOP
}

/**
Expand Down

0 comments on commit cf9adf1

Please sign in to comment.