Skip to content

Commit

Permalink
Merge pull request #18 from weikinhuang/sort-mutators
Browse files Browse the repository at this point in the history
Ability to prioritize mutators
  • Loading branch information
weikinhuang committed Mar 29, 2014
2 parents 65ff5fe + de7cbd9 commit ddbb561
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mutator.alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
// mutator for adding aliased function properties to a class
addMutator("alias", {
priority : 1000,
// the special identifier is "$$alias$$"
onCreate : function(klass) {
var mutatorPrefix = this.propPrefix;
Expand Down
1 change: 1 addition & 0 deletions src/mutator.bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
// mutator for adding bound properties to a class
addMutator("bind", {
priority : 1000,
// the special identifier is "$$bind$$"
onCreate : function(klass, parent) {
var mutatorPrefix = this.propPrefix;
Expand Down
15 changes: 15 additions & 0 deletions src/mutator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ Mutator = function(name, props) {
if (!(this instanceof Mutator)) {
return new Mutator(name, props);
}

/**
* The execution priority of this mutator
*
* @private
* @memberOf Classify.Mutator#
* @member priority
* @type {Number}
*/
this.priority = 100;

extend(this, props);

/**
* The name of the mutator
*
Expand Down Expand Up @@ -118,6 +130,9 @@ getMutators = function(klass) {
throw new Error("Mutator objects can only be instances of \"Mutator\", please use createMutator.");
}
}
mutators.sort(function(a, b) {
return a.priority === b.priority ? 0 : (a.priority > b.priority ? -1 : 1);
});
return mutators;
};

Expand Down
1 change: 1 addition & 0 deletions src/mutator.nowrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
// mutator for adding unwrapped function properties to a class
addMutator("nowrap", {
priority : 1000,
// the special identifier is "$$nowrap$$"
onCreate : function(klass) {
var mutatorPrefix = this.propPrefix;
Expand Down
1 change: 1 addition & 0 deletions src/mutator.static.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
// mutator for adding static properties to a class
addMutator("static", {
priority : 1000,
// the special identifier is "$$static$$"
onCreate : function(klass) {
var mutatorPrefix = this.propPrefix;
Expand Down

0 comments on commit ddbb561

Please sign in to comment.