Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4830

Settings constants for all property names, worthwhile or over-engineering?

$
0
0

@_omairvaiyani wrote:

As our code-base is growing, so too is the assets size and load times. One area of optimisation I have considered is property names. I imagine that the compiler is unable to minify string literals, not to mention the duplication aspect.

Example of status quo:

// controller
name:  computed("firstName", "secondName", function () {  
   return this.get("firstName") + " " + this.get("secondName");
}),

firstName: reads("model.firstName"),

secondName: reads("model.secondName"),

getName: function () {
  return this.get("name");
}

With constants:

 // controller
    import { MODEL_PROPS } from "..path to model";
    const PROPS = {  
       NAME: "name",
       MODEL: "model"
    }
...
[PROPS.NAME]:  computed(MODEL_PROPS.FIRST_NAME, MODEL_PROPS.SECOND_NAME, function () {  
   return this.get(MODEL_PROPS.FIRST_NAME) + " " + this.get(MODEL_PROPS.SECOND_NAME);
}),

[MODEL_PROPS.FIRST_NAME]: reads(`${PROPS.MODEL}.${MODEL_PROPS.FIRST_NAME}`),

[MODEL_PROPS.SECOND_NAME]: reads(`${PROPS.MODEL}.${MODEL_PROPS.SECOND_NAME}`),

getName: function () {
  return this.get(PROPS.NAME);
}

This would be a fairly significant undertaking and one that we’d work towards in stages. However, I would like to know if anyone here has tried to engineering their app to this degree and what your experience has been. Is it worthwhile, or even achievable without grinding development to a halt?

Posts: 3

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4830

Trending Articles