Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 setup lifecycle 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