You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What follows is a suggested draft implementation for WuiText. The idea is that text nodes become wrapped, just like DOM elements do. The wrapper object is very thin, but would allow us to attach logic to all text. An example of this (and implemented below) is to allow text to be a tome, in which case the binding to it (allowing changes to automatically be reflected on-screen without any code required) could be automatic.
WuiDom's setText function would instantiate WuiText out of the content passed to it. At the same time, when people want to instantiate their own text objects, they can do this and use the already existing APIs to deal with text the way they already deal with DOM elements. That is: append, insert, etc. The reason why this would work so easily is because most of those DOM APIs operate on Nodes rather than elements.
WuiText.addContentHandler(function(content){varthat=this;// hot path when change happens on a tomeif(this.sourceTome===content){returncontent.toString();}// slow path when creating the event listener for the first timeif(Tome.isTome(content)){if(this.sourceTome){// a different tome is being set, so cleanup the previous onethis.sourceTome.removeListener(this.tomeListener);}this.sourceTome=content;this.tomeListener=function(){that.set(this.value);};content.on('readable',this.tomeListener);returncontent.toString();}// not a tomereturncontent;});
Final goal:
title.setText('Welcome ',player.name,'!');// player.name is a tome that might change// the code above has now created 3 text nodes, the 2nd of which auto-updates with the tome.
What follows is a suggested draft implementation for WuiText. The idea is that text nodes become wrapped, just like DOM elements do. The wrapper object is very thin, but would allow us to attach logic to all text. An example of this (and implemented below) is to allow text to be a tome, in which case the binding to it (allowing changes to automatically be reflected on-screen without any code required) could be automatic.
WuiDom's
setText
function would instantiate WuiText out of the content passed to it. At the same time, when people want to instantiate their own text objects, they can do this and use the already existing APIs to deal with text the way they already deal with DOM elements. That is: append, insert, etc. The reason why this would work so easily is because most of those DOM APIs operate on Nodes rather than elements.WuiText.js:
Registering a tome text handler:
Final goal:
Poke @micky2be @bjornstar
The text was updated successfully, but these errors were encountered: