vigetlabs / microcosm

Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.
http://code.viget.com/microcosm/
MIT License
487 stars 22 forks source link

Errors when domains don't have some methods #152

Closed djmccormick closed 8 years ago

djmccormick commented 8 years ago

If a domain doesn't implement these functions, Microcosm (10.0.0-rc3) throws errors:

bundle.js:95234 Uncaught TypeError: domain.setup is not a function coming out of addDomain.

djmccormick commented 8 years ago

I fixed it like so:

import Immutable from 'immutable';
import Domain from 'microcosm/domain';

export default class BaseDomain extends Domain { // Must extend.
    getInitialState() {
        return Immutable.Map();
    }

    commit(state) {
        return state.toJS();
    }
}
nhunzaker commented 8 years ago

Huh. We implement safe defaults for those methods:

https://github.com/vigetlabs/microcosm/blob/master/src/domain.js

I wonder if Babel's loose mode class transpiler is doing something goofy. Before I go and blame other projects, I'll make sure we aren't doing anything silly, then I'll see if the output from the transpiler is problematic.