Giter Site home page Giter Site logo

updateAttributes with whitelists about model HOT 2 OPEN

geddy avatar geddy commented on August 30, 2024
updateAttributes with whitelists

from model.

Comments (2)

mde avatar mde commented on August 30, 2024

Can you give us a better idea of what this would look like?

from model.

larzconwell avatar larzconwell commented on August 30, 2024

Here's how I am hackily doing it right now, just overwriting updateAttributes to filter out items

var User = function () {
  this.defineProperties({
    name: {type: 'string', required: true} // Should not be able to change
    homepage: {type: 'string'}
  });
};

User.whitelistParams = ['homepage'];

User = model.register('User', User);

User.prototype._updateAttributes = User.prototype.updateAttributes;
User.prototype.updateAttributes = function updateAttributes (attrs) {
  var safeAttrs = {};

  for (var a in attrs) {
    if (User.whitelistParams.indexOf(a) > -1) {
      safeAttrs[a] = attrs[a];
    }
  }

  return this._updateAttributes(safeAttrs);
};

If adding support in model itself, maybe User.whitelistParams could be changed to something else, like maybe an option for the property definitions.

this.defineProperties({
  name: {type: 'string', required: true}
  homepage: {type: 'string', whitelist: true} 
  // If a whitelist item is included in any of the property definitions, 
  // then enable whitelisting and only allow `whitelist: true` items 
  // to be updated
});

from model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.