state.html revision 1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YUI 3.0</title>
<script type="text/javascript" src="/build/yui.js"></script>
<script type="text/javascript" src="/src/js/State.js"></script>
<script type="text/javascript">
// YUI({
// core: ['*']
// }).use('state', function(Y) {
// YUI({logExclude: {'Event': true}}).use('dump', 'state', function(Y) {
YUI({logInclude: {'Example': true}}).use('dump', 'state', function(Y) {
// YUI({logInclude: {}}).use('dump', 'state', function(Y) {
var newobj = {},
o = {
str: "str",
arr: [
"array1",
true,
{ obj: "obj"},
["array2"]
],
dat: new Date(),
fn: function() {
},
//win: window,
nada: null
};
var configs = new Y.State();
// add a prop
configs.add('myprop', o);
// show all attributes for this item
Y.log("myprop: " + Y.Lang.dump(configs.get('myprop')), 'info', 'Example');
// show a single attribute for this item
Y.log("myprop.str: " + configs.get('myprop', 'str'), 'info', 'Example');
// remove one or more attribute from the item (hash)
configs.remove('myprop', {fn: true});
Y.log("myprop-fn: " + Y.Lang.dump(configs.get('myprop')), 'info', 'Example');
// remove an attribute from the item (str)
configs.remove('myprop', 'dat');
Y.log("myprop-dat: " + Y.Lang.dump(configs.get('myprop')), 'info', 'Example');
// remove one or more attributes from the item (array)
configs.remove('myprop', ['nada']);
Y.log("myprop-nada: " + Y.Lang.dump(configs.get('myprop')), 'info', 'Example');
// add an attribute to an existing prop
configs.add('myprop', {nada:null});
Y.log("myprop+nada: " + Y.Lang.dump(configs.get('myprop')), 'info', 'Example');
// delete a property
configs.remove('myprop');
Y.log("myprop deleted: " + Y.Lang.dump(configs.get('myprop')), 'info', 'Example');
var o2 = Y.clone(o);
// Y.log("clone: " + Y.Lang.dump(o2));
configs.add('myprop', o2);
configs.add('myprop2', {
str: 'str2',
nada: null
});
Y.log("myprop list: " + Y.Lang.dump(configs.list()), 'info', 'Example');
var Y = YUI();
function Main() {
}
Main.NAME = "main";
Main.ATTRS = {
mainA : {
value:"mainA"
},
mainB : {
value:"mainB"
}
}
Main.PLUGINS = [
"mainplugin"
];
function Aggr() {
}
Aggr.NAME = "aggr";
Aggr.ATTRS = {
aggrA : {
value:"aggrA"
}
};
Aggr.PLUGINS = [
"aggplugin"
];
Y.aggregate(Main, Aggr, false, ["ATTRS", "PLUGINS"]);
Y.log(Main.ATTRS, 'info', 'Example');
Y.log(Main.PLUGINS, 'info', 'Example');
});
</script>
<body>
see the console
</body>
</html>