Skip to content

Commit

Permalink
Merge 97a35d3 into 80f6701
Browse files Browse the repository at this point in the history
  • Loading branch information
EAGzzyCSL committed Nov 14, 2017
2 parents 80f6701 + 97a35d3 commit b0b7d4a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function reactionFn(mapState) {
this.setData(mapped);
}

function startMobxReaction(mapState, mapActions) {
function startMobxReaction(mapState, mapActions, isComponent) {
const store = StoreMgr.getStore();
Object.defineProperty(this, '$store', {
enumerable: false,
Expand All @@ -46,11 +46,12 @@ function startMobxReaction(mapState, mapActions) {
}

if (mapActions) {
const actionMount = isComponent ? this.methods = this.methods || {} : this;
let actions = mapActions(store, this.data) || {};
Object.keys(actions).forEach(name => {
warning(this[name] !== undefined, 'Trying to overwrite an existing property.');
warning(actionMount[name] === undefined, 'Trying to overwrite an existing property.');
assert(typeof actions[name] === 'function', 'Actions can only be function.');
this[name] = actions[name];
actionMount[name] = actions[name];
});
}
}
Expand Down Expand Up @@ -85,7 +86,7 @@ export default function observer(mapState, mapActions) {
} else {
const { onLoad, onUnload } = options;
opts.onLoad = function() {
startMobxReaction.call(this, mapState, mapActions);
startMobxReaction.call(this, mapState, mapActions, isComponent);

/* istanbul ignore else */
if (typeof onLoad === 'function') {
Expand Down

0 comments on commit b0b7d4a

Please sign in to comment.