Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Is this a safe strategy for translating can.Map/can.Model attribute names prior to init()?

$
0
0
I have an unfortunate scenario where I must translate attribute names (coming from a server response) prior to initialization on a Map or Model instance.

I settled on this solution below. It works as far I can tell, but I wanted a gut-check on any unforeseen caveats this may present. I had also considered using the "define: {}" form of constructing attributes and simply aliasing all of the attribute names that needed to change, but that seemed ugly and wasteful.
  1. var SomeModel = can.Map.extend({
  2.   setup: function (attrs) {
  3.     return this._super(translatorFn(attrs, newAttrKeys));
  4.   }
  5. });
  6. var model = new SomeModel({ extraLongVerboseName: 'Foo' });
  7. model.attr(); // => { shortName: 'Foo' }


Viewing all articles
Browse latest Browse all 3491

Latest Images

Trending Articles



Latest Images