Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
simplified a bit the patch implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergonz committed Oct 20, 2018
1 parent c1384c8 commit ab98fa2
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,22 @@ function createDefinition(target, methodName, oldDefinition, mixins) {
const wrappedFunc = wrapFunction(mixins)
wrappedFunc[mobxRealMethod] = originalMethod

return new PatchedDefinition(target, methodName, wrappedFunc, oldDefinition)
}

function PatchedDefinition(target, methodName, wrappedFunc, oldDefinition) {
this.get = function() {
return wrappedFunc
}
this.set = function(value) {
if (this === target) {
wrappedFunc[mobxRealMethod] = value
} else {
// when it is an instance of the prototype/a child prototype patch that particular case again separately
// we don't need to pass any mixin functions since the structure is shared
patch(this, methodName, true)
this[methodName] = value
}
return {
[mobxPatchedDefinition]: true,
get: function() {
return wrappedFunc
},
set: function(value) {
if (this === target) {
wrappedFunc[mobxRealMethod] = value
} else {
// when it is an instance of the prototype/a child prototype patch that particular case again separately
// we don't need to pass any mixin functions since the structure is shared
patch(this, methodName, true)
this[methodName] = value
}
},
configurable: true,
enumerable: oldDefinition ? oldDefinition.enumerable : undefined
}
this.enumerable = oldDefinition ? oldDefinition.enumerable : undefined
}
PatchedDefinition.prototype[mobxPatchedDefinition] = true
PatchedDefinition.prototype.configurable = true

0 comments on commit ab98fa2

Please sign in to comment.