-
Notifications
You must be signed in to change notification settings - Fork 369
Closed
Labels
Description
This should be reasonably simple to implement, I'm just pitching the idea.
Let's say I wanted to define a plugin that would serialize an instance to JSON/Javascript with a whitelist or a blacklist. As of right now that is not possible, plus there are currently no model specific settings. Say I defined a plugin with the code below with a beforeDefine hook.
function Plugin (db) {
return {
// This uses the properties and opts passed into the Model constructor.
beforeDefine: function (name, properties, opts) {
// Now we can intercept and add the methods we want.
if (!Array.isArray(opts.visible)) {
return;
}
opts.methods = opts.methods || {};
opts.methods.toJs = function () {
// Code to filter model instance fields based on the fields provided in the opts.visible Array
};
opts.methods.toJson = function () {
return JSON.serialize(opts.methods.toJs());
};
}
};
}Now that is all possible. Does this seem like a reasonable idea to you guys?
Reactions are currently unavailable