Skip to content

Commit

Permalink
3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipskevin committed Jun 23, 2017
1 parent 3093e66 commit 18a81da
Show file tree
Hide file tree
Showing 3 changed files with 413 additions and 0 deletions.
100 changes: 100 additions & 0 deletions dist/amd/can-simple-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*can-simple-map@3.2.0-pre.8#can-simple-map*/
define(function (require, exports, module) {
var Construct = require('can-construct');
var canEvent = require('can-event');
var canBatch = require('can-event/batch');
var assign = require('can-util/js/assign');
var each = require('can-util/js/each');
var types = require('can-types');
var Observation = require('can-observation');
var canSymbol = require('can-symbol');
var canReflect = require('can-reflect');
var singleReference = require('can-util/js/single-reference');
var SimpleMap = Construct.extend({
setup: function (initialData) {
this._data = {};
this.attr(initialData);
},
attr: function (prop, value) {
var self = this;
if (arguments.length === 0) {
Observation.add(this, '__keys');
var data = {};
each(this._data, function (value, prop) {
Observation.add(this, prop);
data[prop] = value;
}, this);
return data;
} else if (arguments.length > 1) {
var had = this._data.hasOwnProperty(prop);
var old = this._data[prop];
this._data[prop] = value;
canBatch.start();
if (!had) {
canEvent.dispatch.call(this, '__keys', []);
}
canEvent.dispatch.call(this, prop, [
value,
old
]);
canBatch.stop();
} else if (typeof prop === 'object') {
canReflect.eachKey(prop, function (value, key) {
self.attr(key, value);
});
} else {
if (prop !== 'constructor') {
Observation.add(this, prop);
return this._data[prop];
}
return this.constructor;
}
},
serialize: function () {
var serialized = {};
Observation.add(this, '__keys');
each(this._data, function (data, prop) {
Observation.add(this, prop);
serialized[prop] = data && typeof data.serialize === 'function' ? data.serialize() : data;
}, this);
return serialized;
},
get: function () {
return this.attr.apply(this, arguments);
},
set: function () {
return this.attr.apply(this, arguments);
}
});
assign(SimpleMap.prototype, canEvent);
if (!types.DefaultMap) {
types.DefaultMap = SimpleMap;
}
SimpleMap.prototype[canSymbol.for('can.onKeyValue')] = function (key, handler) {
var translationHandler = function (ev, newValue, oldValue) {
handler.call(this, newValue, oldValue);
};
singleReference.set(handler, this, translationHandler, key);
this.addEventListener(key, translationHandler);
};
SimpleMap.prototype[canSymbol.for('can.offKeyValue')] = function (key, handler) {
this.removeEventListener(key, singleReference.getAndDelete(handler, this, key));
};
SimpleMap.prototype[canSymbol.for('can.isMapLike')] = true;
SimpleMap.prototype[canSymbol.for('can.isListLike')] = false;
SimpleMap.prototype[canSymbol.for('can.isValueLike')] = false;
SimpleMap.prototype[canSymbol.for('can.getKeyValue')] = SimpleMap.prototype.get;
SimpleMap.prototype[canSymbol.for('can.setKeyValue')] = SimpleMap.prototype.set;
SimpleMap.prototype[canSymbol.for('can.getValue')] = SimpleMap.prototype.get;
SimpleMap.prototype[canSymbol.for('can.setValue')] = SimpleMap.prototype.set;
SimpleMap.prototype[canSymbol.for('can.deleteKeyValue')] = function (prop) {
return this.attr(prop, undefined);
};
SimpleMap.prototype[canSymbol.for('can.keyHasDependencies')] = function (key) {
return false;
};
SimpleMap.prototype[canSymbol.for('can.getKeyDependencies')] = function (key) {
return undefined;
};
module.exports = SimpleMap;
});
98 changes: 98 additions & 0 deletions dist/cjs/can-simple-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*can-simple-map@3.2.0-pre.8#can-simple-map*/
var Construct = require('can-construct');
var canEvent = require('can-event');
var canBatch = require('can-event/batch/batch');
var assign = require('can-util/js/assign/assign');
var each = require('can-util/js/each/each');
var types = require('can-types');
var Observation = require('can-observation');
var canSymbol = require('can-symbol');
var canReflect = require('can-reflect');
var singleReference = require('can-util/js/single-reference/single-reference');
var SimpleMap = Construct.extend({
setup: function (initialData) {
this._data = {};
this.attr(initialData);
},
attr: function (prop, value) {
var self = this;
if (arguments.length === 0) {
Observation.add(this, '__keys');
var data = {};
each(this._data, function (value, prop) {
Observation.add(this, prop);
data[prop] = value;
}, this);
return data;
} else if (arguments.length > 1) {
var had = this._data.hasOwnProperty(prop);
var old = this._data[prop];
this._data[prop] = value;
canBatch.start();
if (!had) {
canEvent.dispatch.call(this, '__keys', []);
}
canEvent.dispatch.call(this, prop, [
value,
old
]);
canBatch.stop();
} else if (typeof prop === 'object') {
canReflect.eachKey(prop, function (value, key) {
self.attr(key, value);
});
} else {
if (prop !== 'constructor') {
Observation.add(this, prop);
return this._data[prop];
}
return this.constructor;
}
},
serialize: function () {
var serialized = {};
Observation.add(this, '__keys');
each(this._data, function (data, prop) {
Observation.add(this, prop);
serialized[prop] = data && typeof data.serialize === 'function' ? data.serialize() : data;
}, this);
return serialized;
},
get: function () {
return this.attr.apply(this, arguments);
},
set: function () {
return this.attr.apply(this, arguments);
}
});
assign(SimpleMap.prototype, canEvent);
if (!types.DefaultMap) {
types.DefaultMap = SimpleMap;
}
SimpleMap.prototype[canSymbol.for('can.onKeyValue')] = function (key, handler) {
var translationHandler = function (ev, newValue, oldValue) {
handler.call(this, newValue, oldValue);
};
singleReference.set(handler, this, translationHandler, key);
this.addEventListener(key, translationHandler);
};
SimpleMap.prototype[canSymbol.for('can.offKeyValue')] = function (key, handler) {
this.removeEventListener(key, singleReference.getAndDelete(handler, this, key));
};
SimpleMap.prototype[canSymbol.for('can.isMapLike')] = true;
SimpleMap.prototype[canSymbol.for('can.isListLike')] = false;
SimpleMap.prototype[canSymbol.for('can.isValueLike')] = false;
SimpleMap.prototype[canSymbol.for('can.getKeyValue')] = SimpleMap.prototype.get;
SimpleMap.prototype[canSymbol.for('can.setKeyValue')] = SimpleMap.prototype.set;
SimpleMap.prototype[canSymbol.for('can.getValue')] = SimpleMap.prototype.get;
SimpleMap.prototype[canSymbol.for('can.setValue')] = SimpleMap.prototype.set;
SimpleMap.prototype[canSymbol.for('can.deleteKeyValue')] = function (prop) {
return this.attr(prop, undefined);
};
SimpleMap.prototype[canSymbol.for('can.keyHasDependencies')] = function (key) {
return false;
};
SimpleMap.prototype[canSymbol.for('can.getKeyDependencies')] = function (key) {
return undefined;
};
module.exports = SimpleMap;
Loading

0 comments on commit 18a81da

Please sign in to comment.