jw-ng-forward
Version:
Temporary package. The default solution for those that want to write Angular 2.x style code in Angular 1.x
44 lines (43 loc) • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
var Metastore = (function () {
function Metastore(namespace) {
this.namespace = namespace;
}
Metastore.prototype._map = function (obj, key) {
if (!Reflect.hasOwnMetadata(this.namespace, obj, key)) {
Reflect.defineMetadata(this.namespace, new Map(), obj, key);
}
return Reflect.getOwnMetadata(this.namespace, obj, key);
};
Metastore.prototype.get = function (key, obj, prop) {
return this._map(obj, prop).get(key);
};
Metastore.prototype.set = function (key, value, obj, prop) {
this._map(obj, prop).set(key, value);
};
Metastore.prototype.has = function (key, obj, prop) {
return this._map(obj, prop).has(key);
};
Metastore.prototype.push = function (key, value, obj, prop) {
if (!this.has(key, obj, prop)) {
this.set(key, [], obj, prop);
}
var store = this.get(key, obj, prop);
if (!Array.isArray(store)) {
throw new Error('Metastores can only push metadata to array values');
}
store.push(value);
};
Metastore.prototype.merge = function (key, value, obj, prop) {
var previous = this.get(key, obj, prop) || {};
var mergedObj = Object.assign({}, previous, value);
this.set(key, mergedObj, obj, prop);
};
Metastore.prototype.forEach = function (callbackFn, obj, prop) {
this._map(obj, prop).forEach(callbackFn);
};
return Metastore;
}());
exports.Metastore = Metastore;