Skip to content

Commit

Permalink
Merge pull request #12 from Turbo87/remove-weakmap
Browse files Browse the repository at this point in the history
Remove `ember-weakmap` dependency
  • Loading branch information
GavinJoyce authored Nov 14, 2017
2 parents d163bd3 + af3dcbe commit 203b0a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 451 deletions.
13 changes: 5 additions & 8 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import WeakMap from 'ember-weakmap';
import Ember from 'ember';

function isEqual(key, a, b) {
return a === b;
}

export default Ember.Mixin.create({
_didChangeAttrsWeakMap: null, //this tracks previous state of any `trackAttrChanges`
_didChangeAttrsBuffer: null, //this tracks previous state of any `trackAttrChanges`
didChangeAttrsConfig: [], //attributes to track

didReceiveAttrs() {
this._super(...arguments);

let weakMap = this.get('_didChangeAttrsWeakMap');
let buffer = this.get('_didChangeAttrsBuffer');

if (weakMap === null) { //first run
if (buffer === null) { //first run
let config = this.get('didChangeAttrsConfig');
let trackedAttrs = config.attrs;
let initialValues = {};
Expand All @@ -24,9 +23,7 @@ export default Ember.Mixin.create({
initialValues[key] = this.get(key);
}

weakMap = new WeakMap();
weakMap.set(this, initialValues);
this.set('_didChangeAttrsWeakMap', weakMap);
this.set('_didChangeAttrsBuffer', initialValues);
}
},

Expand All @@ -37,7 +34,7 @@ export default Ember.Mixin.create({
let equalityFn = config.isEqual || isEqual;

let trackedAttrs = config.attrs;
let oldValues = this.get('_didChangeAttrsWeakMap').get(this);
let oldValues = this.get('_didChangeAttrsBuffer');
let changes = {};

for (let i=0; i<trackedAttrs.length; i++) {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"test": "ember try:each"
},
"dependencies": {
"ember-cli-babel": "^6.6.0",
"ember-weakmap": "2.0.0"
"ember-cli-babel": "^6.6.0"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
Expand Down
Loading

0 comments on commit 203b0a2

Please sign in to comment.