Satyam![]()
This module is an extension to help in the handling of tree-like structures using the Flyweight pattern. It is the basis for gallery-fwt-treeview module, which is a subclass of Y.Widget though I would expect that it can also extend a subclass of Y.View.
It contains a manager (FlyweightTreeManager) class extension which is the factory that provides instances of a node (FlyweightTreeNode) class, which inherits from Y.Base and represents each of the nodes in the tree.
The manager stores the tree internally as a plain object with no methods, events or attributes. It creates and pools a limited number of node object instances which it positions over the internal nodes where the state information is stored. It can handle multiple node types (subclasses of FlyweightTreeNode) delivering the correct type for each node.
The overall memory consumption is very low. Assuming all nodes are of the same type, the number of objects the pool might contain equal the depth of the tree, regardless of the number of nodes on the tree.
This is a set of abstract classes not meant to be instanced directly.
The sample below shows how the tree manager extension is used to extend Y.Widget and create Y.FWTreeView. while Y.FWTreeNode inherints from the tree node class.
The actual implementation is not shown, see gallery-fwt-treeview.
<script src="http://yui.yahooapis.com/3.10.0/build/yui/yui-min.js"></script>YUI.add('gallery-fwt-treeview', function (Y, NAME) {
Y.FWTreeView = Y.Base.create(
NAME,
Y.Widget,
[Y.FlyweightTreeManager],
{
// ......
}
);
Y.FWTreeNode = Y.Base.create(
NAME,
Y.FlyweightNode,
[],
{
// ......
}
);
}, '@VERSION@' ,
{
requires: ['gallery-flyweight-tree', 'widget', 'base-build']
});
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info