Title here
Summary here
Don’t call parent in view properties:
WRONG:
export default $View.declare("ParentView", {
properties: {
title: "I am the title of the ParentView"
},
children: {
titleView: {class: $ChildView}
}
});
export default $View.declare("ChildView", {
properties: {
title: ({parent}) => parent.title // WRONG
},
children: {
titleText: {
class: $TextPrimitive,
text: ({parent}) => parent.title
}
}
});
GOOD:
export default $View.declare("ParentView", {
properties: {
title: "I am the title of the ParentView"
},
children: {
titleView: {class: $ChildView, title: ({parent}) => parent.title} // GOOD
}
}
export default $View.declare("ChildView", {
properties: {
title: "I am a default title"
},
children: {
titleText: {class: $TextPrimitive, text: ({parent}) => parent.title}
}
}
Prefer update child property using method, instead of binding:
WRONG:
export default $View.declare("MyView", {
properties: {
title: ""
},
children: {
titleText: {class: $TextPrimitive, text: ({parent}) => parent.title}
}
}
let view = new MyView();
view.title = "I am the title of the View";
GOOD:
export default $View.declare("MyView", {
children: {
titleText: {class: $TextPrimitive}
},
methods: {
setTitle: function (title) {
this.titleText = title;
}
}
}
let view = new MyView();
view.setTitle("I am the title of the View");
Add model as class property if data view is a model:
WRONG:
export default $View.declare("ChannelView", {
children: {
channelName: {class: $TextPrimitive, text: ({parent}) => parent.data.name}
}
}
GOOD:
import $Channel from "@Channel";
export default $View.declare("ChannelView", {
properties: {
data: {class: $Channel} // GOOD
},
children: {
channelName: {class: $TextPrimitive, text: ({parent}) => parent.data.name}
}
}
Create statics for states to be able to reuse them
WRONG:
export default $View.declare("MyView", {
methods: {
manipulateStates: function () {
this.setState("slided");
this.setState("!slided");
}
}
});
GOOD:
export default $View.declare("MyView", {
statics: {
STATE_SLIDED: "slided"
},
methods: {
manipulateStates: function () {
this.setState(this.statics.STATE_SLIDED);
this.setState("!" + this.statics.STATE_SLIDED);
}
}
});