< QmlWeb‎ | Qml.js

Difference between revisions of "QmlWeb/Qml.js/Design Questions and Decisions"

Line 44: Line 44:
 
The possibilities to handle that are:
 
The possibilities to handle that are:
 
; Always create a namespace, not only when imported with ''as''
 
; Always create a namespace, not only when imported with ''as''
 +
* Makes generated code bigger and less readable
 
; ?
 
; ?

Revision as of 15:53, 4 March 2015

This page intends to collect questions about software architecute and software design, pros and cons as well as the decisions made on the topic.

Runtime Architecture

Getter/Setter Technique

Possibilities:

C++ style getters and setters
this.width(); and this.setWidth(width);
  • pro/con: C++ style
  • pro: fast in all browsers
Transparent getter/setter using Object.defineProperty
Object.defineProperty(this, "width", { get function(){}, set: function(){} });
  • pro: nice while debugging
  • con: worse performance in IE
  • con: horrible performance in Firefox
Transparent getter/setter using literal notation
  • pro: nice while debugging
  • con: worse performance in IE
  • con: you can't use object literals and inheritance at the same time in a standard compliant manner


Benchmark: http://jsperf.com/getter-setter/7

Decision: Use C++ style getters and setters

Storing properties

As we're using setters and getters in either way, we need to store the actual property value separated. There're multiple possibilities for that:

Private member using closures
Private member using like _width
Using property objects and direct object references
Using property indexes and a properties array
  • pro: If done right, it might provide weak references
Using a properties object and access it per name
  • con: Bad bad bad performance

Handling bindings

Let the bindings depend on each other and make them set the value on update
  • pro: Seems logically like the right thing. After all it's the bindings that define the dependencies
  • con: How to know when a property gets overwritten and thus the binding is invalidated?
Let the properties depend on each other and make them reevaluate the binding when needed


Module Handling

The relevant point here is how to handle the case that in two different contexts, two different modules are loaded, which contain two different types with the same name. The possibilities to handle that are:

Always create a namespace, not only when imported with as
  • Makes generated code bigger and less readable
?

This page was last edited on 4 March 2015, at 15:53. Content is available under Creative Commons License SA 4.0 unless otherwise noted.