Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Close @todo: Add non-enumerable getter and setter for metadata functionality" #1347

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions lib/collection/property-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,39 @@ PropertyBase = function PropertyBase (definition) {

// call the meta extraction functions to create the object where all keys that are prefixed with underscore can be
// stored. more details on that can be retrieved from the propertyExtractMeta function itself.
// @todo: make this a closed function to do getter and setter which is non enumerable
var src = definition && definition.info || definition,
meta = _(src).pickBy(PropertyBase.propertyIsMeta).mapKeys(PropertyBase.propertyUnprefixMeta).value();

if (_.keys(meta).length) {
this._ = _.isObject(this._) ?
/* istanbul ignore next */
_.mergeDefined(this._, meta) :
meta;
}
var _meta = {}; // variable to store metadata

var extractAndSetMeta = function (definition) {
var src = definition && definition.info || definition;
var meta = _(src).pickBy(PropertyBase.propertyIsMeta).mapKeys(PropertyBase.propertyUnprefixMeta).value();

if (_.keys(meta).length) {
_meta = _.isObject(_meta) ? _.mergeDefined(_meta, meta) : meta;
}
};

// calling function for Initial extraction and setting of meta
extractAndSetMeta(definition);

// Getter method for metadata
Object.defineProperty(this, 'getMeta', {
enumerable: false,
configurable: true,
value: function () {
return _.cloneDeep(_meta);
}
});

// Setter method for metadata
Object.defineProperty(this, 'setMeta', {
enumerable: false,
configurable: true,
value: function (newMeta) {
if (_.isObject(newMeta)) {
_meta = _.mergeDefined(_meta, newMeta);
}
}
});
};

_.assign(PropertyBase.prototype, /** @lends PropertyBase.prototype */ {
Expand Down