1 module uim.vue.base.obj; 2 3 import uim.vue; 4 5 @safe: 6 7 @safe: 8 9 class DVUEObj { 10 this() {} 11 this(string aName) { this(); _name = aName; } 12 13 mixin(TProperty!("string", "name")); 14 unittest { 15 assert(VUEObj.name("test").name == "test"); 16 assert(VUEObj("test").name == "test"); 17 } 18 19 20 /// Data object for the Vue instance or component 21 mixin(XStringAA!"data"); 22 O data(this O)(string name) { return data(name, name); } 23 unittest { 24 assert(VUEObj.data("a","b").data == ["a":"b"]); 25 assert(VUEObj.data("a","b").data == ["a":"b"]); 26 assert(VUEObj.data("a","b").data("x","y").data == ["a":"b", "x":"y"]); 27 // assert(VUEObj.data("a","b").data("x","y").removeData("a").data == ["x":"y"]); 28 assert(VUEObj.data("a","b").data("a","y").data == ["a":"y"]); 29 // assert(VUEObj.data("a","b").clearData.data == null); 30 } 31 unittest { 32 /// TODO 33 } 34 35 mixin(XStringAA!"methods"); 36 unittest { 37 assert(VUEObj.methods("a","b").methods == ["a":"b"]); 38 assert(VUEObj.methods("a","b").methods == ["a":"b"]); 39 assert(VUEObj.methods("a","b").methods("x","y").methods == ["a":"b", "x":"y"]); 40 // assert(VUEObj.methods("a","b").methods("x","y").removeMethods("a").methods == ["x":"y"]); 41 assert(VUEObj.methods("a","b").methods("a","y").methods == ["a":"y"]); 42 // assert(VUEObj.methods("a","b").clearMethods.methods == null); 43 } 44 unittest { 45 /// TODO 46 } 47 48 string[string] _computed; 49 auto computed() { return _computed; } 50 O computed(this O)(string[string] contents) { foreach(name,value; contents) _computed[name] = "function(){"~value~"}"; return cast(O)this; } 51 O computed(this O)(string name, string content) { _computed[name] = "function(){"~content~"}"; return cast(O)this; } 52 O computed(this O)(string name, string getContent, string setContent) { 53 string[] result; 54 if (getContent) result ~= "get:function(){"~getContent~"}"; 55 if (setContent) result ~= "set:function(){"~setContent~"}"; 56 _computed[name] = "{"~result.join(",")~"}"; 57 return cast(O)this; 58 } 59 unittest { 60 assert(VUEObj.computed("a","b").computed == ["a":"function(){b}"]); 61 assert(VUEObj.computed(["a":"b"]).computed == ["a":"function(){b}"]); 62 assert(VUEObj.computed("a","b","c").computed == ["a":"{get:function(){b},set:function(){c}}"]); 63 assert(VUEObj.computed("a",null,"c").computed == ["a":"{set:function(){c}}"]); 64 assert(VUEObj.computed("a","b",null).computed == ["a":"{get:function(){b}}"]); 65 assert(VUEObj.computed("a","b").computed("a","b","c").computed == ["a":"{get:function(){b},set:function(){c}}"]); 66 } 67 68 mixin(XStringAA!"watch"); 69 unittest { 70 /// TODO 71 } 72 73 mixin(XString!"template_"); 74 O template_(this O)(DH5Obj h5){ _template_ ~= h5.toString; return cast(O)this; } 75 unittest { 76 assert(VUEObj.template_("a").template_ == "a"); 77 assert(VUEObj.template_("a").template_("x").template_ == "ax"); 78 } 79 80 string[string] settings() { 81 string[string] results; 82 83 if (_methods) { 84 string[] funcs; 85 foreach(k, v; _methods) funcs ~= k~"{"~v~"}"; 86 results["methods"] = "{"~funcs.sort.join(",")~"}"; 87 } 88 if (_computed) results["computed"] = _computed.toJS(true); 89 if (_watch) { 90 string[string] _inner; 91 foreach(k, v; _watch) _inner[k] = "function(value){"~v~"}"; 92 results["watch"] = _inner.toJS(true); 93 } 94 95 if (_template_) results["template"] = "`"~_template_~"`"; 96 97 return results; 98 } 99 100 bool opEquals(string txt) { return toString == txt; } 101 override string toString() { return ""; } 102 } 103 auto VUEObj() { return new DVUEObj(); } 104 auto VUEObj(string aName) { return new DVUEObj(aName); } 105 unittest{ 106 107 }