vasille 2.0.5 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +4 -0
  2. package/cdn/es2015.js +651 -665
  3. package/cdn/es5.js +737 -675
  4. package/flow-typed/vasille.js +2643 -835
  5. package/lib/binding/attribute.js +7 -2
  6. package/lib/binding/class.js +2 -2
  7. package/lib/binding/style.js +1 -1
  8. package/lib/core/core.js +57 -7
  9. package/lib/functional/components.js +17 -0
  10. package/lib/functional/merge.js +41 -0
  11. package/lib/functional/models.js +26 -0
  12. package/lib/functional/options.js +1 -0
  13. package/lib/functional/reactivity.js +33 -0
  14. package/lib/functional/stack.js +127 -0
  15. package/lib/index.js +2 -7
  16. package/lib/models/array-model.js +9 -0
  17. package/lib/models/object-model.js +28 -14
  18. package/lib/node/app.js +20 -11
  19. package/lib/node/node.js +186 -538
  20. package/lib/node/watch.js +5 -13
  21. package/lib/spec/html.js +1 -0
  22. package/lib/spec/react.js +1 -0
  23. package/lib/spec/svg.js +1 -0
  24. package/lib/v/index.js +23 -0
  25. package/lib/value/expression.js +8 -5
  26. package/lib/views/array-view.js +6 -10
  27. package/lib/views/base-view.js +11 -22
  28. package/lib/views/map-view.js +4 -9
  29. package/lib/views/object-view.js +4 -7
  30. package/lib/views/repeat-node.js +6 -18
  31. package/lib/views/set-view.js +4 -11
  32. package/package.json +3 -1
  33. package/types/binding/attribute.d.ts +2 -2
  34. package/types/core/core.d.ts +27 -41
  35. package/types/functional/components.d.ts +4 -0
  36. package/types/functional/merge.d.ts +1 -0
  37. package/types/functional/models.d.ts +10 -0
  38. package/types/functional/options.d.ts +23 -0
  39. package/types/functional/reactivity.d.ts +11 -0
  40. package/types/functional/stack.d.ts +24 -0
  41. package/types/index.d.ts +3 -7
  42. package/types/models/array-model.d.ts +1 -0
  43. package/types/models/object-model.d.ts +2 -0
  44. package/types/node/app.d.ts +19 -17
  45. package/types/node/node.d.ts +55 -378
  46. package/types/node/watch.d.ts +9 -15
  47. package/types/spec/html.d.ts +975 -0
  48. package/types/spec/react.d.ts +4 -0
  49. package/types/spec/svg.d.ts +314 -0
  50. package/types/v/index.d.ts +32 -0
  51. package/types/value/expression.d.ts +6 -19
  52. package/types/views/array-view.d.ts +3 -4
  53. package/types/views/base-view.d.ts +8 -16
  54. package/types/views/map-view.d.ts +2 -3
  55. package/types/views/object-view.d.ts +2 -3
  56. package/types/views/repeat-node.d.ts +7 -8
  57. package/types/views/set-view.d.ts +2 -3
  58. package/types/core/executor.d.ts +0 -87
  59. package/types/core/signal.d.ts +0 -35
  60. package/types/core/slot.d.ts +0 -45
  61. package/types/node/interceptor.d.ts +0 -50
  62. package/types/views/repeater.d.ts +0 -38
package/cdn/es5.js CHANGED
@@ -12,6 +12,14 @@ var __spreadArray = function (to, from, pack) {
12
12
  return to.concat(ar || Array.prototype.slice.call(from));
13
13
  };
14
14
 
15
+ var __assign = function(o1, o2) {
16
+ for (let i in o2) {
17
+ o1[i] = o2[i];
18
+ }
19
+
20
+ return o1;
21
+ }
22
+
15
23
  var Set = window.Set || /** @class */ (function (_super) {
16
24
  __extends(Set, _super);
17
25
  function Set(set) {
@@ -165,6 +173,42 @@ var Map = window.Map || /** @class */ (function (_super) {
165
173
 
166
174
  return Map;
167
175
  }(Array));
176
+
177
+ window.Reflect = window.Reflect || {
178
+ has: function (obj, p) {
179
+ for (var i in obj) {
180
+ if (i == p) return true;
181
+ }
182
+ return false;
183
+ },
184
+ ownKeys: function (obj) {
185
+ let ret = [];
186
+
187
+ for (var i in obj) {
188
+ if (obj.hasOwnProperty(i)) {
189
+ ret.push(i);
190
+ }
191
+ }
192
+
193
+ return ret;
194
+ }
195
+ }
196
+
197
+ window.Proxy = window.Proxy || function (obj) {
198
+ return obj;
199
+ };
200
+ // ./lib-es5/v/index.js
201
+
202
+ var v = __assign(__assign({ ref: function (value) {
203
+ return current.ref(value);
204
+ }, expr: expr, of: valueOf, sv: setValue, alwaysFalse: new Reference(false), app: app, component: component, fragment: fragment, extension: extension, text: text, tag: tag, create: create }, vx), { merge: merge, destructor: function () {
205
+ return current.destroy.bind(current);
206
+ }, runOnDestroy: function (callback) {
207
+ current.runOnDestroy(callback);
208
+ } });
209
+
210
+ window.v = v;
211
+
168
212
  // ./lib-es5/models/model.js
169
213
 
170
214
 
@@ -321,13 +365,14 @@ var ObjectModel = /** @class */ (function (_super) {
321
365
  function ObjectModel(obj) {
322
366
  if (obj === void 0) { obj = {}; }
323
367
  var _this = this; _super.call(this);
368
+ _this.container = Object.create(null);
324
369
  Object.defineProperty(_this, 'listener', {
325
370
  value: new Listener,
326
371
  writable: false,
327
372
  configurable: false
328
373
  });
329
374
  for (var i in obj) {
330
- Object.defineProperty(_this, i, {
375
+ Object.defineProperty(_this.container, i, {
331
376
  value: obj[i],
332
377
  configurable: true,
333
378
  writable: true,
@@ -343,8 +388,7 @@ var ObjectModel = /** @class */ (function (_super) {
343
388
  * @return {*}
344
389
  */
345
390
  ObjectModel.prototype.get = function (key) {
346
- var ts = this;
347
- return ts[key];
391
+ return this.container[key];
348
392
  };
349
393
  /**
350
394
  * Sets an object property value
@@ -353,21 +397,19 @@ var ObjectModel = /** @class */ (function (_super) {
353
397
  * @return {ObjectModel} a pointer to this
354
398
  */
355
399
  ObjectModel.prototype.set = function (key, v) {
356
- var ts = this;
357
- // eslint-disable-next-line no-prototype-builtins
358
- if (ts.hasOwnProperty(key)) {
359
- this.listener.emitRemoved(key, ts[key]);
360
- ts[key] = v;
400
+ if (Reflect.has(this.container, key)) {
401
+ this.listener.emitRemoved(key, this.container[key]);
402
+ this.container[key] = v;
361
403
  }
362
404
  else {
363
- Object.defineProperty(ts, key, {
405
+ Object.defineProperty(this.container, key, {
364
406
  value: v,
365
407
  configurable: true,
366
408
  writable: true,
367
409
  enumerable: true
368
410
  });
369
411
  }
370
- this.listener.emitAdded(key, ts[key]);
412
+ this.listener.emitAdded(key, this.container[key]);
371
413
  return this;
372
414
  };
373
415
  /**
@@ -375,12 +417,28 @@ var ObjectModel = /** @class */ (function (_super) {
375
417
  * @param key {string} property name
376
418
  */
377
419
  ObjectModel.prototype.delete = function (key) {
378
- var ts = this;
379
- if (ts[key]) {
380
- this.listener.emitRemoved(key, ts[key]);
381
- delete ts[key];
420
+ if (this.container[key]) {
421
+ this.listener.emitRemoved(key, this.container[key]);
422
+ delete this.container[key];
382
423
  }
383
424
  };
425
+ ObjectModel.prototype.proxy = function () {
426
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
427
+ var ts = this;
428
+ return new Proxy(this.container, {
429
+ get: function (target, p) {
430
+ return ts.get(p);
431
+ },
432
+ set: function (target, p, value) {
433
+ ts.set(p, value);
434
+ return true;
435
+ },
436
+ deleteProperty: function (target, p) {
437
+ ts.delete(p);
438
+ return true;
439
+ }
440
+ });
441
+ };
384
442
  ObjectModel.prototype.enableReactivity = function () {
385
443
  this.listener.enableReactivity();
386
444
  };
@@ -564,6 +622,15 @@ var ArrayModel = /** @class */ (function (_super) {
564
622
  }
565
623
  return _this;
566
624
  }
625
+ // proxy
626
+ ArrayModel.prototype.proxy = function () {
627
+ return new Proxy(this, {
628
+ set: function (target, p, value) {
629
+ target.splice(parseInt(p), 1, value);
630
+ return true;
631
+ }
632
+ });
633
+ };
567
634
  Object.defineProperty(ArrayModel.prototype, "last", {
568
635
  /* Array members */
569
636
  /**
@@ -774,6 +841,287 @@ var ArrayModel = /** @class */ (function (_super) {
774
841
 
775
842
  window.ArrayModel = ArrayModel;
776
843
 
844
+ // ./lib-es5/functional/merge.js
845
+ function merge(main) {
846
+ var targets = [];
847
+ for (var _i = 1; _i < arguments.length; _i++) {
848
+ targets[_i - 1] = arguments[_i];
849
+ }
850
+ function refactorClass(obj) {
851
+ if (Array.isArray(obj.class)) {
852
+ var out_1 = {
853
+ $: []
854
+ };
855
+ obj.class.forEach(function (item) {
856
+ if (item instanceof IValue) {
857
+ out_1.$.push(item);
858
+ }
859
+ else if (typeof item === 'string') {
860
+ out_1[item] = true;
861
+ }
862
+ else if (typeof item === 'object') {
863
+ Object.assign(out_1, item);
864
+ }
865
+ });
866
+ obj.class = out_1;
867
+ }
868
+ }
869
+ refactorClass(main);
870
+ targets.forEach(function (target) {
871
+ Reflect.ownKeys(target).forEach(function (prop) {
872
+ var _a;
873
+ if (!Reflect.has(main, prop)) {
874
+ main[prop] = target[prop];
875
+ }
876
+ else if (typeof main[prop] === 'object' && typeof target[prop] === 'object') {
877
+ if (prop === 'class') {
878
+ refactorClass(target);
879
+ }
880
+ if (prop === '$' && Array.isArray(main[prop]) && Array.isArray(target[prop])) {
881
+ (_a = main.$).push.apply(_a, target.$);
882
+ }
883
+ else {
884
+ merge(main[prop], target[prop]);
885
+ }
886
+ }
887
+ });
888
+ });
889
+ }
890
+
891
+ window.merge = merge;
892
+
893
+ // ./lib-es5/functional/stack.js
894
+ function app(renderer) {
895
+ return function (node, opts) {
896
+ return new App(node, opts).runFunctional(renderer, opts);
897
+ };
898
+ }
899
+ function component(renderer) {
900
+ return function (opts, callback) {
901
+ var component = new Component(opts);
902
+ if (!(current instanceof Fragment))
903
+ throw userError('missing parent node', 'out-of-context');
904
+ var ret;
905
+ if (callback)
906
+ opts.slot = callback;
907
+ current.create(component, function (node) {
908
+ ret = node.runFunctional(renderer, opts);
909
+ });
910
+ return ret;
911
+ };
912
+ }
913
+ function fragment(renderer) {
914
+ return function (opts, callback) {
915
+ var frag = new Fragment(opts);
916
+ if (!(current instanceof Fragment))
917
+ throw userError('missing parent node', 'out-of-context');
918
+ if (callback)
919
+ opts.slot = callback;
920
+ current.create(frag);
921
+ return frag.runFunctional(renderer, opts);
922
+ };
923
+ }
924
+ function extension(renderer) {
925
+ return function (opts, callback) {
926
+ var ext = new Extension(opts);
927
+ if (!(current instanceof Fragment))
928
+ throw userError('missing parent node', 'out-of-context');
929
+ if (callback)
930
+ opts.slot = callback;
931
+ current.create(ext);
932
+ return ext.runFunctional(renderer, opts);
933
+ };
934
+ }
935
+ function tag(name, opts, callback) {
936
+ if (!(current instanceof Fragment))
937
+ throw userError('missing parent node', 'out-of-context');
938
+ return {
939
+ node: current.tag(name, opts, function (node) {
940
+ callback && node.runFunctional(callback);
941
+ })
942
+ };
943
+ }
944
+ function create(node, callback) {
945
+ if (!(current instanceof Fragment))
946
+ throw userError('missing current node', 'out-of-context');
947
+ current.create(node, function (node) {
948
+ var args = [];
949
+ for (var _i = 1; _i < arguments.length; _i++) {
950
+ args[_i - 1] = arguments[_i];
951
+ }
952
+ callback && node.runFunctional.apply(node, __spreadArray([callback], args, false));
953
+ });
954
+ return node;
955
+ }
956
+ var vx = {
957
+ if: function (condition, callback) {
958
+ if (current instanceof Fragment) {
959
+ current.if(condition, function (node) { return node.runFunctional(callback); });
960
+ }
961
+ else {
962
+ throw userError("wrong use of `v.if` function", "logic-error");
963
+ }
964
+ },
965
+ else: function (callback) {
966
+ if (current instanceof Fragment) {
967
+ current.else(function (node) { return node.runFunctional(callback); });
968
+ }
969
+ else {
970
+ throw userError("wrong use of `v.else` function", "logic-error");
971
+ }
972
+ },
973
+ elif: function (condition, callback) {
974
+ if (current instanceof Fragment) {
975
+ current.elif(condition, function (node) { return node.runFunctional(callback); });
976
+ }
977
+ else {
978
+ throw userError("wrong use of `v.elif` function", "logic-error");
979
+ }
980
+ },
981
+ for: function (model, callback) {
982
+ if (model instanceof ArrayModel) {
983
+ // for arrays T & K are the same type
984
+ create(new ArrayView({ model: model }), callback);
985
+ }
986
+ else if (model instanceof MapModel) {
987
+ create(new MapView({ model: model }), callback);
988
+ }
989
+ else if (model instanceof SetModel) {
990
+ // for sets T & K are the same type
991
+ create(new SetView({ model: model }), callback);
992
+ }
993
+ else if (model instanceof ObjectModel) {
994
+ // for objects K is always string
995
+ create(new ObjectView({ model: model }), callback);
996
+ }
997
+ else {
998
+ throw userError("wrong use of `v.for` function", 'wrong-model');
999
+ }
1000
+ },
1001
+ watch: function (model, callback) {
1002
+ var opts = { model: model };
1003
+ create(new Watch(opts), callback);
1004
+ },
1005
+ nextTick: function (callback) {
1006
+ var node = current;
1007
+ window.setTimeout(function () {
1008
+ node.runFunctional(callback);
1009
+ }, 0);
1010
+ }
1011
+ };
1012
+
1013
+ window.app = app;
1014
+ window.component = component;
1015
+ window.fragment = fragment;
1016
+ window.extension = extension;
1017
+ window.tag = tag;
1018
+ window.create = create;
1019
+ window.vx = vx;
1020
+
1021
+ // ./lib-es5/functional/models.js
1022
+ function arrayModel(arr) {
1023
+ if (arr === void 0) { arr = []; }
1024
+ if (!current)
1025
+ throw userError('missing parent node', 'out-of-context');
1026
+ return current.register(new ArrayModel(arr)).proxy();
1027
+ }
1028
+ function mapModel(map) {
1029
+ if (map === void 0) { map = []; }
1030
+ if (!current)
1031
+ throw userError('missing parent node', 'out-of-context');
1032
+ return current.register(new MapModel(map));
1033
+ }
1034
+ function setModel(arr) {
1035
+ if (arr === void 0) { arr = []; }
1036
+ if (!current)
1037
+ throw userError('missing parent node', 'out-of-context');
1038
+ return current.register(new SetModel(arr));
1039
+ }
1040
+ function objectModel(obj) {
1041
+ if (obj === void 0) { obj = {}; }
1042
+ if (!current)
1043
+ throw userError('missing parent node', 'out-of-context');
1044
+ return current.register(new ObjectModel(obj));
1045
+ }
1046
+
1047
+ window.arrayModel = arrayModel;
1048
+ window.mapModel = mapModel;
1049
+ window.setModel = setModel;
1050
+ window.objectModel = objectModel;
1051
+
1052
+ // ./lib-es5/functional/options.js
1053
+
1054
+
1055
+
1056
+ // ./lib-es5/functional/reactivity.js
1057
+ function ref(value) {
1058
+ var ref = current.ref(value);
1059
+ return [ref, function (value) { return ref.$ = value; }];
1060
+ }
1061
+ function mirror(value) {
1062
+ return current.mirror(value);
1063
+ }
1064
+ function forward(value) {
1065
+ return current.forward(value);
1066
+ }
1067
+ function point(value) {
1068
+ return current.point(value);
1069
+ }
1070
+ function expr(func) {
1071
+ var values = [];
1072
+ for (var _i = 1; _i < arguments.length; _i++) {
1073
+ values[_i - 1] = arguments[_i];
1074
+ }
1075
+ return current.expr.apply(current, __spreadArray([func], values, false));
1076
+ }
1077
+ function watch(func) {
1078
+ var values = [];
1079
+ for (var _i = 1; _i < arguments.length; _i++) {
1080
+ values[_i - 1] = arguments[_i];
1081
+ }
1082
+ current.watch.apply(current, __spreadArray([func], values, false));
1083
+ }
1084
+ function valueOf(value) {
1085
+ return value.$;
1086
+ }
1087
+ function setValue(ref, value) {
1088
+ if (ref instanceof Pointer && value instanceof IValue) {
1089
+ ref.point(value);
1090
+ }
1091
+ else {
1092
+ ref.$ = value instanceof IValue ? value.$ : value;
1093
+ }
1094
+ }
1095
+
1096
+ window.ref = ref;
1097
+ window.mirror = mirror;
1098
+ window.forward = forward;
1099
+ window.point = point;
1100
+ window.expr = expr;
1101
+ window.watch = watch;
1102
+ window.valueOf = valueOf;
1103
+ window.setValue = setValue;
1104
+
1105
+ // ./lib-es5/functional/components.js
1106
+ function text(text) {
1107
+ if (!(current instanceof Fragment))
1108
+ throw userError('missing parent node', 'out-of-context');
1109
+ ;
1110
+ current.text(text);
1111
+ }
1112
+ function debug(text) {
1113
+ if (!(current instanceof Fragment))
1114
+ throw userError('missing parent node', 'out-of-context');
1115
+ current.debug(text);
1116
+ }
1117
+ function predefine(slot, predefined) {
1118
+ return slot || predefined;
1119
+ }
1120
+
1121
+ window.text = text;
1122
+ window.debug = debug;
1123
+ window.predefine = predefine;
1124
+
777
1125
  // ./lib-es5/core/signal.js
778
1126
  /**
779
1127
  * Signal is an event generator
@@ -1225,6 +1573,18 @@ window.IValue = IValue;
1225
1573
 
1226
1574
 
1227
1575
 
1576
+ // ./lib-es5/spec/svg.js
1577
+
1578
+
1579
+
1580
+ // ./lib-es5/spec/react.js
1581
+
1582
+
1583
+
1584
+ // ./lib-es5/spec/html.js
1585
+
1586
+
1587
+
1228
1588
  // ./lib-es5/value/expression.js
1229
1589
  /**
1230
1590
  * Bind some values to one expression
@@ -1233,13 +1593,22 @@ window.IValue = IValue;
1233
1593
  */
1234
1594
  var Expression = /** @class */ (function (_super) {
1235
1595
  __extends(Expression, _super);
1236
- function Expression(func, link, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
1596
+ /**
1597
+ * Creates a function bounded to N values
1598
+ * @param func {Function} the function to bound
1599
+ * @param values
1600
+ * @param link {Boolean} links immediately if true
1601
+ */
1602
+ function Expression(func, link) {
1603
+ var values = [];
1604
+ for (var _i = 2; _i < arguments.length; _i++) {
1605
+ values[_i - 2] = arguments[_i];
1606
+ }
1237
1607
  var _this = _super.call(this, false) || this;
1238
1608
  /**
1239
1609
  * Expression will link different handler for each value of list
1240
1610
  */
1241
1611
  _this.linkedFunc = [];
1242
- var values = [v1, v2, v3, v4, v5, v6, v7, v8, v9].filter(function (v) { return v instanceof IValue; });
1243
1612
  var handler = function (i) {
1244
1613
  if (i != null) {
1245
1614
  _this.valuesCache[i] = _this.values[i].$;
@@ -1248,14 +1617,12 @@ var Expression = /** @class */ (function (_super) {
1248
1617
  };
1249
1618
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1250
1619
  // @ts-ignore
1251
- _this.valuesCache = values.map(function (iValue) { return iValue.$; });
1620
+ _this.valuesCache = values.map(function (item) { return item.$; });
1252
1621
  _this.sync = new Reference(func.apply(_this, _this.valuesCache));
1253
1622
  var i = 0;
1254
1623
  values.forEach(function () {
1255
1624
  _this.linkedFunc.push(handler.bind(_this, Number(i++)));
1256
1625
  });
1257
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1258
- // @ts-ignore
1259
1626
  _this.values = values;
1260
1627
  _this.func = handler;
1261
1628
  if (link) {
@@ -1519,6 +1886,15 @@ var Binding = /** @class */ (function (_super) {
1519
1886
  window.Binding = Binding;
1520
1887
 
1521
1888
  // ./lib-es5/core/core.js
1889
+ var current = null;
1890
+ var currentStack = [];
1891
+ function stack(node) {
1892
+ currentStack.push(current);
1893
+ current = node;
1894
+ }
1895
+ function unstack() {
1896
+ current = currentStack.pop();
1897
+ }
1522
1898
  /**
1523
1899
  * Private stuff of a reactive object
1524
1900
  * @class ReactivePrivate
@@ -1556,14 +1932,14 @@ var ReactivePrivate = /** @class */ (function (_super) {
1556
1932
  return _this;
1557
1933
  }
1558
1934
  ReactivePrivate.prototype.destroy = function () {
1559
- var _a;
1560
1935
  this.watch.forEach(function (value) { return value.destroy(); });
1561
1936
  this.watch.clear();
1562
1937
  this.bindings.forEach(function (binding) { return binding.destroy(); });
1563
1938
  this.bindings.clear();
1564
1939
  this.models.forEach(function (model) { return model.disableReactivity(); });
1565
1940
  this.models.clear();
1566
- (_a = this.freezeExpr) === null || _a === void 0 ? void 0 : _a.destroy();
1941
+ this.freezeExpr && this.freezeExpr.destroy();
1942
+ this.onDestroy && this.onDestroy();
1567
1943
  _super.prototype.destroy.call(this);
1568
1944
  };
1569
1945
  return ReactivePrivate;
@@ -1576,11 +1952,23 @@ var ReactivePrivate = /** @class */ (function (_super) {
1576
1952
  */
1577
1953
  var Reactive = /** @class */ (function (_super) {
1578
1954
  __extends(Reactive, _super);
1579
- function Reactive($) {
1955
+ function Reactive(input, $) {
1580
1956
  var _this = this; _super.call(this);
1957
+ _this.input = input;
1581
1958
  _this.$ = $ || new ReactivePrivate;
1959
+ _this.seal();
1582
1960
  return _this;
1583
1961
  }
1962
+ Object.defineProperty(Reactive.prototype, "parent", {
1963
+ /**
1964
+ * Get parent node
1965
+ */
1966
+ get: function () {
1967
+ return this.$.parent;
1968
+ },
1969
+ enumerable: false,
1970
+ configurable: true
1971
+ });
1584
1972
  /**
1585
1973
  * Create a reference
1586
1974
  * @param value {*} value to reference
@@ -1629,12 +2017,31 @@ var Reactive = /** @class */ (function (_super) {
1629
2017
  this.$.models.add(model);
1630
2018
  return model;
1631
2019
  };
1632
- Reactive.prototype.watch = function (func, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
2020
+ /**
2021
+ * Creates a watcher
2022
+ * @param func {function} function to run on any argument change
2023
+ * @param values
2024
+ */
2025
+ Reactive.prototype.watch = function (func) {
2026
+ var values = [];
2027
+ for (var _i = 1; _i < arguments.length; _i++) {
2028
+ values[_i - 1] = arguments[_i];
2029
+ }
1633
2030
  var $ = this.$;
1634
- $.watch.add(new Expression(func, !this.$.frozen, v1, v2, v3, v4, v5, v6, v7, v8, v9));
2031
+ $.watch.add(new (Expression.bind.apply(Expression, __spreadArray([void 0, func, !this.$.frozen], values, false)))());
1635
2032
  };
1636
- Reactive.prototype.bind = function (func, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
1637
- var res = new Expression(func, !this.$.frozen, v1, v2, v3, v4, v5, v6, v7, v8, v9);
2033
+ /**
2034
+ * Creates a computed value
2035
+ * @param func {function} function to run on any argument change
2036
+ * @param values
2037
+ * @return {IValue} the created ivalue
2038
+ */
2039
+ Reactive.prototype.expr = function (func) {
2040
+ var values = [];
2041
+ for (var _i = 1; _i < arguments.length; _i++) {
2042
+ values[_i - 1] = arguments[_i];
2043
+ }
2044
+ var res = new (Expression.bind.apply(Expression, __spreadArray([void 0, func, !this.$.frozen], values, false)))();
1638
2045
  var $ = this.$;
1639
2046
  $.watch.add(res);
1640
2047
  return res;
@@ -1697,6 +2104,32 @@ var Reactive = /** @class */ (function (_super) {
1697
2104
  }, true, cond);
1698
2105
  return this;
1699
2106
  };
2107
+ Reactive.prototype.init = function () {
2108
+ this.applyOptions(this.input);
2109
+ this.compose(this.input);
2110
+ };
2111
+ Reactive.prototype.applyOptions = function (input) {
2112
+ // empty
2113
+ };
2114
+ Reactive.prototype.compose = function (input) {
2115
+ // empty
2116
+ };
2117
+ Reactive.prototype.runFunctional = function (f) {
2118
+ var args = [];
2119
+ for (var _i = 1; _i < arguments.length; _i++) {
2120
+ args[_i - 1] = arguments[_i];
2121
+ }
2122
+ stack(this);
2123
+ // yet another ts bug
2124
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2125
+ // @ts-ignore
2126
+ var result = f.apply(void 0, args);
2127
+ unstack();
2128
+ return result;
2129
+ };
2130
+ Reactive.prototype.runOnDestroy = function (func) {
2131
+ this.$.onDestroy = func;
2132
+ };
1700
2133
  Reactive.prototype.destroy = function () {
1701
2134
  _super.prototype.destroy.call(this);
1702
2135
  this.$.destroy();
@@ -1706,6 +2139,7 @@ var Reactive = /** @class */ (function (_super) {
1706
2139
  }(Destroyable));
1707
2140
 
1708
2141
 
2142
+ window.current = current;
1709
2143
  window.ReactivePrivate = ReactivePrivate;
1710
2144
  window.Reactive = Reactive;
1711
2145
 
@@ -1750,10 +2184,11 @@ var Fragment = /** @class */ (function (_super) {
1750
2184
  __extends(Fragment, _super);
1751
2185
  /**
1752
2186
  * Constructs a Vasille Node
2187
+ * @param input
1753
2188
  * @param $ {FragmentPrivate}
1754
2189
  */
1755
- function Fragment($) {
1756
- var _this = _super.call(this, $ || new FragmentPrivate) || this;
2190
+ function Fragment(input, $) {
2191
+ var _this = _super.call(this, input, $ || new FragmentPrivate) || this;
1757
2192
  /**
1758
2193
  * The children list
1759
2194
  * @type Array
@@ -1782,36 +2217,14 @@ var Fragment = /** @class */ (function (_super) {
1782
2217
  var $ = this.$;
1783
2218
  $.preinit(app, parent);
1784
2219
  };
1785
- /**
1786
- * Initialize node
1787
- */
1788
- Fragment.prototype.init = function () {
1789
- this.createWatchers();
1790
- this.created();
1791
- this.compose();
1792
- this.mounted();
1793
- return this;
1794
- };
1795
- /** To be overloaded: created event handler */
1796
- Fragment.prototype.created = function () {
1797
- // empty
1798
- };
1799
- /** To be overloaded: mounted event handler */
1800
- Fragment.prototype.mounted = function () {
1801
- // empty
2220
+ Fragment.prototype.compose = function (input) {
2221
+ _super.prototype.compose.call(this, input);
2222
+ input.slot && input.slot(this);
1802
2223
  };
1803
2224
  /** To be overloaded: ready event handler */
1804
2225
  Fragment.prototype.ready = function () {
1805
2226
  // empty
1806
2227
  };
1807
- /** To be overloaded: watchers creation milestone */
1808
- Fragment.prototype.createWatchers = function () {
1809
- // empty
1810
- };
1811
- /** To be overloaded: DOM creation milestone */
1812
- Fragment.prototype.compose = function () {
1813
- // empty
1814
- };
1815
2228
  /**
1816
2229
  * Pushes a node to children immediately
1817
2230
  * @param node {Fragment} A node to push
@@ -1858,7 +2271,7 @@ var Fragment = /** @class */ (function (_super) {
1858
2271
  var child = this.findFirstChild();
1859
2272
  var $ = this.$;
1860
2273
  if (child) {
1861
- $.app.run.insertBefore(child, node);
2274
+ child.parentElement.insertBefore(node, child);
1862
2275
  }
1863
2276
  else if ($.next) {
1864
2277
  $.next.insertAdjacent(node);
@@ -1875,14 +2288,9 @@ var Fragment = /** @class */ (function (_super) {
1875
2288
  Fragment.prototype.text = function (text, cb) {
1876
2289
  var $ = this.$;
1877
2290
  var node = new TextNode();
1878
- var textValue = text instanceof IValue ? text : this.ref(text);
1879
- node.preinit($.app, this, textValue);
2291
+ node.preinit($.app, this, text);
1880
2292
  this.pushNode(node);
1881
- if (cb) {
1882
- $.app.run.callCallback(function () {
1883
- cb(node);
1884
- });
1885
- }
2293
+ cb && cb(node);
1886
2294
  };
1887
2295
  Fragment.prototype.debug = function (text) {
1888
2296
  if (this.$.app.debugUi) {
@@ -1890,39 +2298,36 @@ var Fragment = /** @class */ (function (_super) {
1890
2298
  node.preinit(this.$.app, this, text);
1891
2299
  this.pushNode(node);
1892
2300
  }
1893
- return this;
1894
2301
  };
1895
- Fragment.prototype.tag = function (tagName, cb) {
2302
+ /**
2303
+ * Defines a tag element
2304
+ * @param tagName {String} the tag name
2305
+ * @param input
2306
+ * @param cb {function(Tag, *)} callback
2307
+ */
2308
+ Fragment.prototype.tag = function (tagName, input, cb) {
1896
2309
  var $ = this.$;
1897
- var node = new Tag();
2310
+ var node = new Tag(input);
2311
+ input.slot = cb || input.slot;
1898
2312
  node.preinit($.app, this, tagName);
1899
2313
  node.init();
1900
2314
  this.pushNode(node);
1901
- $.app.run.callCallback(function () {
1902
- if (cb) {
1903
- cb(node, node.node);
1904
- }
1905
- node.ready();
1906
- });
2315
+ node.ready();
2316
+ return node.node;
1907
2317
  };
1908
2318
  /**
1909
2319
  * Defines a custom element
1910
2320
  * @param node {Fragment} vasille element to insert
1911
2321
  * @param callback {function($ : *)}
1912
- * @param callback1 {function($ : *)}
1913
2322
  */
1914
- Fragment.prototype.create = function (node, callback, callback1) {
2323
+ Fragment.prototype.create = function (node, callback) {
1915
2324
  var $ = this.$;
1916
2325
  node.$.parent = this;
1917
2326
  node.preinit($.app, this);
1918
- if (callback) {
1919
- callback(node);
1920
- }
1921
- if (callback1) {
1922
- callback1(node);
1923
- }
2327
+ node.input.slot = callback || node.input.slot;
1924
2328
  this.pushNode(node);
1925
- node.init().ready();
2329
+ node.init();
2330
+ node.ready();
1926
2331
  };
1927
2332
  /**
1928
2333
  * Defines an if node
@@ -1931,35 +2336,28 @@ var Fragment = /** @class */ (function (_super) {
1931
2336
  * @return {this}
1932
2337
  */
1933
2338
  Fragment.prototype.if = function (cond, cb) {
1934
- return this.switch({ cond: cond, cb: cb });
1935
- };
1936
- /**
1937
- * Defines a if-else node
1938
- * @param ifCond {IValue} `if` condition
1939
- * @param ifCb {function(Fragment)} Call-back to create `if` child nodes
1940
- * @param elseCb {function(Fragment)} Call-back to create `else` child nodes
1941
- */
1942
- Fragment.prototype.if_else = function (ifCond, ifCb, elseCb) {
1943
- return this.switch({ cond: ifCond, cb: ifCb }, { cond: trueIValue, cb: elseCb });
1944
- };
1945
- /**
1946
- * Defines a switch nodes: Will break after first true condition
1947
- * @param cases {...{ cond : IValue, cb : function(Fragment) }} cases
1948
- * @return {INode}
1949
- */
1950
- Fragment.prototype.switch = function () {
1951
- var cases = [];
1952
- for (var _i = 0; _i < arguments.length; _i++) {
1953
- cases[_i] = arguments[_i];
1954
- }
1955
- var $ = this.$;
1956
2339
  var node = new SwitchedNode();
1957
- node.preinit($.app, this);
2340
+ node.preinit(this.$.app, this);
1958
2341
  node.init();
1959
2342
  this.pushNode(node);
1960
- node.setCases(cases);
2343
+ node.addCase(this.case(cond, cb));
1961
2344
  node.ready();
1962
- return this;
2345
+ };
2346
+ Fragment.prototype.else = function (cb) {
2347
+ if (this.lastChild instanceof SwitchedNode) {
2348
+ this.lastChild.addCase(this.default(cb));
2349
+ }
2350
+ else {
2351
+ throw userError('wrong `else` function use', 'logic-error');
2352
+ }
2353
+ };
2354
+ Fragment.prototype.elif = function (cond, cb) {
2355
+ if (this.lastChild instanceof SwitchedNode) {
2356
+ this.lastChild.addCase(this.case(cond, cb));
2357
+ }
2358
+ else {
2359
+ throw userError('wrong `elif` function use', 'logic-error');
2360
+ }
1963
2361
  };
1964
2362
  /**
1965
2363
  * Create a case for switch
@@ -2029,15 +2427,18 @@ var TextNodePrivate = /** @class */ (function (_super) {
2029
2427
  /**
2030
2428
  * Pre-initializes a text node
2031
2429
  * @param app {AppNode} the app node
2430
+ * @param parent
2032
2431
  * @param text {IValue}
2033
2432
  */
2034
2433
  TextNodePrivate.prototype.preinitText = function (app, parent, text) {
2035
2434
  var _this = this;
2036
2435
  _super.prototype.preinit.call(this, app, parent);
2037
- this.node = document.createTextNode(text.$);
2038
- this.bindings.add(new Expression(function (v) {
2039
- _this.node.replaceData(0, -1, v);
2040
- }, true, text));
2436
+ this.node = document.createTextNode(text instanceof IValue ? text.$ : text);
2437
+ if (text instanceof IValue) {
2438
+ this.bindings.add(new Expression(function (v) {
2439
+ _this.node.replaceData(0, -1, v);
2440
+ }, true, text));
2441
+ }
2041
2442
  };
2042
2443
  /**
2043
2444
  * Clear node data
@@ -2057,7 +2458,7 @@ var TextNode = /** @class */ (function (_super) {
2057
2458
  __extends(TextNode, _super);
2058
2459
  function TextNode($) {
2059
2460
  if ($ === void 0) { $ = new TextNodePrivate(); }
2060
- var _this = _super.call(this, $) || this;
2461
+ var _this = _super.call(this, {}, $) || this;
2061
2462
  _this.seal();
2062
2463
  return _this;
2063
2464
  }
@@ -2112,10 +2513,11 @@ var INode = /** @class */ (function (_super) {
2112
2513
  __extends(INode, _super);
2113
2514
  /**
2114
2515
  * Constructs a base node
2516
+ * @param input
2115
2517
  * @param $ {?INodePrivate}
2116
2518
  */
2117
- function INode($) {
2118
- var _this = _super.call(this, $ || new INodePrivate) || this;
2519
+ function INode(input, $) {
2520
+ var _this = _super.call(this, input, $ || new INodePrivate) || this;
2119
2521
  _this.seal();
2120
2522
  return _this;
2121
2523
  }
@@ -2129,26 +2531,6 @@ var INode = /** @class */ (function (_super) {
2129
2531
  enumerable: false,
2130
2532
  configurable: true
2131
2533
  });
2132
- /**
2133
- * Initialize node
2134
- */
2135
- INode.prototype.init = function () {
2136
- this.createWatchers();
2137
- this.createAttrs();
2138
- this.createStyle();
2139
- this.created();
2140
- this.compose();
2141
- this.mounted();
2142
- return this;
2143
- };
2144
- /** To be overloaded: attributes creation milestone */
2145
- INode.prototype.createAttrs = function () {
2146
- // empty
2147
- };
2148
- /** To be overloaded: $style attributes creation milestone */
2149
- INode.prototype.createStyle = function () {
2150
- // empty
2151
- };
2152
2534
  /**
2153
2535
  * Bind attribute value
2154
2536
  * @param name {String} name of attribute
@@ -2159,18 +2541,20 @@ var INode = /** @class */ (function (_super) {
2159
2541
  var attr = new AttributeBinding(this, name, value);
2160
2542
  $.bindings.add(attr);
2161
2543
  };
2162
- INode.prototype.bindAttr = function (name, calculator, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
2163
- var $ = this.$;
2164
- var expr = this.bind(calculator, v1, v2, v3, v4, v5, v6, v7, v8, v9);
2165
- $.bindings.add(new AttributeBinding(this, name, expr));
2166
- };
2167
2544
  /**
2168
2545
  * Set attribute value
2169
2546
  * @param name {string} name of attribute
2170
2547
  * @param value {string} value
2171
2548
  */
2172
2549
  INode.prototype.setAttr = function (name, value) {
2173
- this.$.app.run.setAttribute(this.$.node, name, value);
2550
+ if (typeof value === 'boolean') {
2551
+ if (value) {
2552
+ this.$.node.setAttribute(name, "");
2553
+ }
2554
+ }
2555
+ else {
2556
+ this.$.node.setAttribute(name, "".concat(value));
2557
+ }
2174
2558
  return this;
2175
2559
  };
2176
2560
  /**
@@ -2178,22 +2562,15 @@ var INode = /** @class */ (function (_super) {
2178
2562
  * @param cl {string} Class name
2179
2563
  */
2180
2564
  INode.prototype.addClass = function (cl) {
2181
- this.$.app.run.addClass(this.$.node, cl);
2565
+ this.$.node.classList.add(cl);
2182
2566
  return this;
2183
2567
  };
2184
2568
  /**
2185
2569
  * Adds some CSS classes
2186
2570
  * @param cls {...string} classes names
2187
2571
  */
2188
- INode.prototype.addClasses = function () {
2189
- var _this = this;
2190
- var cls = [];
2191
- for (var _i = 0; _i < arguments.length; _i++) {
2192
- cls[_i] = arguments[_i];
2193
- }
2194
- cls.forEach(function (cl) {
2195
- _this.$.app.run.addClass(_this.$.node, cl);
2196
- });
2572
+ INode.prototype.removeClasse = function (cl) {
2573
+ this.$.node.classList.remove(cl);
2197
2574
  return this;
2198
2575
  };
2199
2576
  /**
@@ -2229,17 +2606,6 @@ var INode = /** @class */ (function (_super) {
2229
2606
  }
2230
2607
  return this;
2231
2608
  };
2232
- INode.prototype.bindStyle = function (name, calculator, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
2233
- var $ = this.$;
2234
- var expr = this.bind(calculator, v1, v2, v3, v4, v5, v6, v7, v8, v9);
2235
- if ($.node instanceof HTMLElement) {
2236
- $.bindings.add(new StyleBinding(this, name, expr));
2237
- }
2238
- else {
2239
- throw userError('style can be applied to HTML elements only', 'non-html-element');
2240
- }
2241
- return this;
2242
- };
2243
2609
  /**
2244
2610
  * Sets a style property value
2245
2611
  * @param prop {string} Property name
@@ -2247,10 +2613,10 @@ var INode = /** @class */ (function (_super) {
2247
2613
  */
2248
2614
  INode.prototype.setStyle = function (prop, value) {
2249
2615
  if (this.$.node instanceof HTMLElement) {
2250
- this.$.app.run.setStyle(this.$.node, prop, value);
2616
+ this.$.node.style.setProperty(prop, value);
2251
2617
  }
2252
2618
  else {
2253
- throw userError("Style can be setted for HTML elements only", "non-html-element");
2619
+ throw userError("Style can be set for HTML elements only", "non-html-element");
2254
2620
  }
2255
2621
  return this;
2256
2622
  };
@@ -2264,387 +2630,8 @@ var INode = /** @class */ (function (_super) {
2264
2630
  this.$.node.addEventListener(name, handler, options);
2265
2631
  return this;
2266
2632
  };
2267
- /**
2268
- * @param handler {function (MouseEvent)}
2269
- * @param options {Object | boolean}
2270
- */
2271
- INode.prototype.oncontextmenu = function (handler, options) {
2272
- return this.listen("contextmenu", handler, options);
2273
- };
2274
- /**
2275
- * @param handler {function (MouseEvent)}
2276
- * @param options {Object | boolean}
2277
- */
2278
- INode.prototype.onmousedown = function (handler, options) {
2279
- return this.listen("mousedown", handler, options);
2280
- };
2281
- /**
2282
- * @param handler {function (MouseEvent)}
2283
- * @param options {Object | boolean}
2284
- */
2285
- INode.prototype.onmouseenter = function (handler, options) {
2286
- return this.listen("mouseenter", handler, options);
2287
- };
2288
- /**
2289
- * @param handler {function (MouseEvent)}
2290
- * @param options {Object | boolean}
2291
- */
2292
- INode.prototype.onmouseleave = function (handler, options) {
2293
- return this.listen("mouseleave", handler, options);
2294
- };
2295
- /**
2296
- * @param handler {function (MouseEvent)}
2297
- * @param options {Object | boolean}
2298
- */
2299
- INode.prototype.onmousemove = function (handler, options) {
2300
- return this.listen("mousemove", handler, options);
2301
- };
2302
- /**
2303
- * @param handler {function (MouseEvent)}
2304
- * @param options {Object | boolean}
2305
- */
2306
- INode.prototype.onmouseout = function (handler, options) {
2307
- return this.listen("mouseout", handler, options);
2308
- };
2309
- /**
2310
- * @param handler {function (MouseEvent)}
2311
- * @param options {Object | boolean}
2312
- */
2313
- INode.prototype.onmouseover = function (handler, options) {
2314
- return this.listen("mouseover", handler, options);
2315
- };
2316
- /**
2317
- * @param handler {function (MouseEvent)}
2318
- * @param options {Object | boolean}
2319
- */
2320
- INode.prototype.onmouseup = function (handler, options) {
2321
- return this.listen("mouseup", handler, options);
2322
- };
2323
- /**
2324
- * @param handler {function (MouseEvent)}
2325
- * @param options {Object | boolean}
2326
- */
2327
- INode.prototype.onclick = function (handler, options) {
2328
- return this.listen("click", handler, options);
2329
- };
2330
- /**
2331
- * @param handler {function (MouseEvent)}
2332
- * @param options {Object | boolean}
2333
- */
2334
- INode.prototype.ondblclick = function (handler, options) {
2335
- return this.listen("dblclick", handler, options);
2336
- };
2337
- /**
2338
- * @param handler {function (FocusEvent)}
2339
- * @param options {Object | boolean}
2340
- */
2341
- INode.prototype.onblur = function (handler, options) {
2342
- return this.listen("blur", handler, options);
2343
- };
2344
- /**
2345
- * @param handler {function (FocusEvent)}
2346
- * @param options {Object | boolean}
2347
- */
2348
- INode.prototype.onfocus = function (handler, options) {
2349
- return this.listen("focus", handler, options);
2350
- };
2351
- /**
2352
- * @param handler {function (FocusEvent)}
2353
- * @param options {Object | boolean}
2354
- */
2355
- INode.prototype.onfocusin = function (handler, options) {
2356
- return this.listen("focusin", handler, options);
2357
- };
2358
- /**
2359
- * @param handler {function (FocusEvent)}
2360
- * @param options {Object | boolean}
2361
- */
2362
- INode.prototype.onfocusout = function (handler, options) {
2363
- return this.listen("focusout", handler, options);
2364
- };
2365
- /**
2366
- * @param handler {function (KeyboardEvent)}
2367
- * @param options {Object | boolean}
2368
- */
2369
- INode.prototype.onkeydown = function (handler, options) {
2370
- return this.listen("keydown", handler, options);
2371
- };
2372
- /**
2373
- * @param handler {function (KeyboardEvent)}
2374
- * @param options {Object | boolean}
2375
- */
2376
- INode.prototype.onkeyup = function (handler, options) {
2377
- return this.listen("keyup", handler, options);
2378
- };
2379
- /**
2380
- * @param handler {function (KeyboardEvent)}
2381
- * @param options {Object | boolean}
2382
- */
2383
- INode.prototype.onkeypress = function (handler, options) {
2384
- return this.listen("keypress", handler, options);
2385
- };
2386
- /**
2387
- * @param handler {function (TouchEvent)}
2388
- * @param options {Object | boolean}
2389
- */
2390
- INode.prototype.ontouchstart = function (handler, options) {
2391
- return this.listen("touchstart", handler, options);
2392
- };
2393
- /**
2394
- * @param handler {function (TouchEvent)}
2395
- * @param options {Object | boolean}
2396
- */
2397
- INode.prototype.ontouchmove = function (handler, options) {
2398
- return this.listen("touchmove", handler, options);
2399
- };
2400
- /**
2401
- * @param handler {function (TouchEvent)}
2402
- * @param options {Object | boolean}
2403
- */
2404
- INode.prototype.ontouchend = function (handler, options) {
2405
- return this.listen("touchend", handler, options);
2406
- };
2407
- /**
2408
- * @param handler {function (TouchEvent)}
2409
- * @param options {Object | boolean}
2410
- */
2411
- INode.prototype.ontouchcancel = function (handler, options) {
2412
- return this.listen("touchcancel", handler, options);
2413
- };
2414
- /**
2415
- * @param handler {function (WheelEvent)}
2416
- * @param options {Object | boolean}
2417
- */
2418
- INode.prototype.onwheel = function (handler, options) {
2419
- return this.listen("wheel", handler, options);
2420
- };
2421
- /**
2422
- * @param handler {function (ProgressEvent)}
2423
- * @param options {Object | boolean}
2424
- */
2425
- INode.prototype.onabort = function (handler, options) {
2426
- return this.listen("abort", handler, options);
2427
- };
2428
- /**
2429
- * @param handler {function (ProgressEvent)}
2430
- * @param options {Object | boolean}
2431
- */
2432
- INode.prototype.onerror = function (handler, options) {
2433
- return this.listen("error", handler, options);
2434
- };
2435
- /**
2436
- * @param handler {function (ProgressEvent)}
2437
- * @param options {Object | boolean}
2438
- */
2439
- INode.prototype.onload = function (handler, options) {
2440
- return this.listen("load", handler, options);
2441
- };
2442
- /**
2443
- * @param handler {function (ProgressEvent)}
2444
- * @param options {Object | boolean}
2445
- */
2446
- INode.prototype.onloadend = function (handler, options) {
2447
- return this.listen("loadend", handler, options);
2448
- };
2449
- /**
2450
- * @param handler {function (ProgressEvent)}
2451
- * @param options {Object | boolean}
2452
- */
2453
- INode.prototype.onloadstart = function (handler, options) {
2454
- return this.listen("loadstart", handler, options);
2455
- };
2456
- /**
2457
- * @param handler {function (ProgressEvent)}
2458
- * @param options {Object | boolean}
2459
- */
2460
- INode.prototype.onprogress = function (handler, options) {
2461
- return this.listen("progress", handler, options);
2462
- };
2463
- /**
2464
- * @param handler {function (ProgressEvent)}
2465
- * @param options {Object | boolean}
2466
- */
2467
- INode.prototype.ontimeout = function (handler, options) {
2468
- return this.listen("timeout", handler, options);
2469
- };
2470
- /**
2471
- * @param handler {function (DragEvent)}
2472
- * @param options {Object | boolean}
2473
- */
2474
- INode.prototype.ondrag = function (handler, options) {
2475
- return this.listen("drag", handler, options);
2476
- };
2477
- /**
2478
- * @param handler {function (DragEvent)}
2479
- * @param options {Object | boolean}
2480
- */
2481
- INode.prototype.ondragend = function (handler, options) {
2482
- return this.listen("dragend", handler, options);
2483
- };
2484
- /**
2485
- * @param handler {function (DragEvent)}
2486
- * @param options {Object | boolean}
2487
- */
2488
- INode.prototype.ondragenter = function (handler, options) {
2489
- return this.listen("dragenter", handler, options);
2490
- };
2491
- /**
2492
- * @param handler {function (DragEvent)}
2493
- * @param options {Object | boolean}
2494
- */
2495
- INode.prototype.ondragexit = function (handler, options) {
2496
- return this.listen("dragexit", handler, options);
2497
- };
2498
- /**
2499
- * @param handler {function (DragEvent)}
2500
- * @param options {Object | boolean}
2501
- */
2502
- INode.prototype.ondragleave = function (handler, options) {
2503
- return this.listen("dragleave", handler, options);
2504
- };
2505
- /**
2506
- * @param handler {function (DragEvent)}
2507
- * @param options {Object | boolean}
2508
- */
2509
- INode.prototype.ondragover = function (handler, options) {
2510
- return this.listen("dragover", handler, options);
2511
- };
2512
- /**
2513
- * @param handler {function (DragEvent)}
2514
- * @param options {Object | boolean}
2515
- */
2516
- INode.prototype.ondragstart = function (handler, options) {
2517
- return this.listen("dragstart", handler, options);
2518
- };
2519
- /**
2520
- * @param handler {function (DragEvent)}
2521
- * @param options {Object | boolean}
2522
- */
2523
- INode.prototype.ondrop = function (handler, options) {
2524
- return this.listen("drop", handler, options);
2525
- };
2526
- /**
2527
- * @param handler {function (PointerEvent)}
2528
- * @param options {Object | boolean}
2529
- */
2530
- INode.prototype.onpointerover = function (handler, options) {
2531
- return this.listen("pointerover", handler, options);
2532
- };
2533
- /**
2534
- * @param handler {function (PointerEvent)}
2535
- * @param options {Object | boolean}
2536
- */
2537
- INode.prototype.onpointerenter = function (handler, options) {
2538
- return this.listen("pointerenter", handler, options);
2539
- };
2540
- /**
2541
- * @param handler {function (PointerEvent)}
2542
- * @param options {Object | boolean}
2543
- */
2544
- INode.prototype.onpointerdown = function (handler, options) {
2545
- return this.listen("pointerdown", handler, options);
2546
- };
2547
- /**
2548
- * @param handler {function (PointerEvent)}
2549
- * @param options {Object | boolean}
2550
- */
2551
- INode.prototype.onpointermove = function (handler, options) {
2552
- return this.listen("pointermove", handler, options);
2553
- };
2554
- /**
2555
- * @param handler {function (PointerEvent)}
2556
- * @param options {Object | boolean}
2557
- */
2558
- INode.prototype.onpointerup = function (handler, options) {
2559
- return this.listen("pointerup", handler, options);
2560
- };
2561
- /**
2562
- * @param handler {function (PointerEvent)}
2563
- * @param options {Object | boolean}
2564
- */
2565
- INode.prototype.onpointercancel = function (handler, options) {
2566
- return this.listen("pointercancel", handler, options);
2567
- };
2568
- /**
2569
- * @param handler {function (PointerEvent)}
2570
- * @param options {Object | boolean}
2571
- */
2572
- INode.prototype.onpointerout = function (handler, options) {
2573
- return this.listen("pointerout", handler, options);
2574
- };
2575
- /**
2576
- * @param handler {function (PointerEvent)}
2577
- * @param options {Object | boolean}
2578
- */
2579
- INode.prototype.onpointerleave = function (handler, options) {
2580
- return this.listen("pointerleave", handler, options);
2581
- };
2582
- /**
2583
- * @param handler {function (PointerEvent)}
2584
- * @param options {Object | boolean}
2585
- */
2586
- INode.prototype.ongotpointercapture = function (handler, options) {
2587
- return this.listen("gotpointercapture", handler, options);
2588
- };
2589
- /**
2590
- * @param handler {function (PointerEvent)}
2591
- * @param options {Object | boolean}
2592
- */
2593
- INode.prototype.onlostpointercapture = function (handler, options) {
2594
- return this.listen("lostpointercapture", handler, options);
2595
- };
2596
- /**
2597
- * @param handler {function (AnimationEvent)}
2598
- * @param options {Object | boolean}
2599
- */
2600
- INode.prototype.onanimationstart = function (handler, options) {
2601
- return this.listen("animationstart", handler, options);
2602
- };
2603
- /**
2604
- * @param handler {function (AnimationEvent)}
2605
- * @param options {Object | boolean}
2606
- */
2607
- INode.prototype.onanimationend = function (handler, options) {
2608
- return this.listen("animationend", handler, options);
2609
- };
2610
- /**
2611
- * @param handler {function (AnimationEvent)}
2612
- * @param options {Object | boolean}
2613
- */
2614
- INode.prototype.onanimationiteraton = function (handler, options) {
2615
- return this.listen("animationiteration", handler, options);
2616
- };
2617
- /**
2618
- * @param handler {function (ClipboardEvent)}
2619
- * @param options {Object | boolean}
2620
- */
2621
- INode.prototype.onclipboardchange = function (handler, options) {
2622
- return this.listen("clipboardchange", handler, options);
2623
- };
2624
- /**
2625
- * @param handler {function (ClipboardEvent)}
2626
- * @param options {Object | boolean}
2627
- */
2628
- INode.prototype.oncut = function (handler, options) {
2629
- return this.listen("cut", handler, options);
2630
- };
2631
- /**
2632
- * @param handler {function (ClipboardEvent)}
2633
- * @param options {Object | boolean}
2634
- */
2635
- INode.prototype.oncopy = function (handler, options) {
2636
- return this.listen("copy", handler, options);
2637
- };
2638
- /**
2639
- * @param handler {function (ClipboardEvent)}
2640
- * @param options {Object | boolean}
2641
- */
2642
- INode.prototype.onpaste = function (handler, options) {
2643
- return this.listen("paste", handler, options);
2644
- };
2645
2633
  INode.prototype.insertAdjacent = function (node) {
2646
- var $ = this.$;
2647
- $.app.run.insertBefore($.node, node);
2634
+ this.$.node.parentNode.insertBefore(node, this.$.node);
2648
2635
  };
2649
2636
  /**
2650
2637
  * A v-show & ngShow alternative
@@ -2671,19 +2658,106 @@ var INode = /** @class */ (function (_super) {
2671
2658
  * bind HTML
2672
2659
  * @param value {IValue}
2673
2660
  */
2674
- INode.prototype.html = function (value) {
2661
+ INode.prototype.bindDomApi = function (name, value) {
2675
2662
  var $ = this.$;
2676
2663
  var node = $.node;
2677
2664
  if (node instanceof HTMLElement) {
2678
- node.innerHTML = value.$;
2665
+ node[name] = value.$;
2679
2666
  this.watch(function (v) {
2680
- node.innerHTML = v;
2667
+ node[name] = v;
2681
2668
  }, value);
2682
2669
  }
2683
2670
  else {
2684
2671
  throw userError("HTML can be bound for HTML nodes only", "dom-error");
2685
2672
  }
2686
2673
  };
2674
+ INode.prototype.applyOptions = function (options) {
2675
+ var _this = this;
2676
+ options["v:attr"] && Object.keys(options["v:attr"]).forEach(function (name) {
2677
+ var value = options["v:attr"][name];
2678
+ if (value instanceof IValue) {
2679
+ _this.attr(name, value);
2680
+ }
2681
+ else {
2682
+ _this.setAttr(name, value);
2683
+ }
2684
+ });
2685
+ if (options.class) {
2686
+ var handleClass_1 = function (name, value) {
2687
+ if (value instanceof IValue) {
2688
+ _this.floatingClass(value, name);
2689
+ }
2690
+ else if (value && name !== '$') {
2691
+ _this.addClass(name);
2692
+ }
2693
+ else {
2694
+ _this.removeClasse(name);
2695
+ }
2696
+ };
2697
+ if (Array.isArray(options.class)) {
2698
+ options.class.forEach(function (item) {
2699
+ if (item instanceof IValue) {
2700
+ _this.bindClass(item);
2701
+ }
2702
+ else if (typeof item == "string") {
2703
+ _this.addClass(item);
2704
+ }
2705
+ else {
2706
+ Reflect.ownKeys(item).forEach(function (name) {
2707
+ handleClass_1(name, item[name]);
2708
+ });
2709
+ }
2710
+ });
2711
+ }
2712
+ else {
2713
+ options.class.$.forEach(function (item) {
2714
+ _this.bindClass(item);
2715
+ });
2716
+ Reflect.ownKeys(options.class).forEach(function (name) {
2717
+ handleClass_1(name, options.class[name]);
2718
+ });
2719
+ }
2720
+ }
2721
+ options.style && Object.keys(options.style).forEach(function (name) {
2722
+ var value = options.style[name];
2723
+ if (value instanceof IValue) {
2724
+ _this.style(name, value);
2725
+ }
2726
+ else if (typeof value === "string") {
2727
+ _this.setStyle(name, value);
2728
+ }
2729
+ else {
2730
+ if (value[0] instanceof IValue) {
2731
+ _this.style(name, _this.expr(function (v) { return v + value[1]; }, value[0]));
2732
+ }
2733
+ else {
2734
+ _this.setStyle(name, value[0] + value[1]);
2735
+ }
2736
+ }
2737
+ });
2738
+ options["v:events"] && Object.keys(options["v:events"]).forEach(function (name) {
2739
+ _this.listen(name, options["v:events"][name]);
2740
+ });
2741
+ if (options["v:bind"]) {
2742
+ var inode_1 = this.node;
2743
+ Reflect.ownKeys(options["v:bind"]).forEach(function (k) {
2744
+ var value = options["v:bind"][k];
2745
+ if (k === 'value' && (inode_1 instanceof HTMLInputElement || inode_1 instanceof HTMLTextAreaElement)) {
2746
+ inode_1.oninput = function () { return value.$ = inode_1.value; };
2747
+ }
2748
+ else if (k === 'checked' && inode_1 instanceof HTMLInputElement) {
2749
+ inode_1.oninput = function () { return value.$ = inode_1.checked; };
2750
+ }
2751
+ else if (k === 'volume' && inode_1 instanceof HTMLMediaElement) {
2752
+ inode_1.onvolumechange = function () { return value.$ = inode_1.volume; };
2753
+ }
2754
+ _this.bindDomApi(k, value);
2755
+ });
2756
+ }
2757
+ options["v:set"] && Object.keys(options["v:set"]).forEach(function (key) {
2758
+ _this.node[key] = options["v:set"][key];
2759
+ });
2760
+ };
2687
2761
  return INode;
2688
2762
  }(Fragment));
2689
2763
 
@@ -2694,8 +2768,8 @@ var INode = /** @class */ (function (_super) {
2694
2768
  */
2695
2769
  var Tag = /** @class */ (function (_super) {
2696
2770
  __extends(Tag, _super);
2697
- function Tag() {
2698
- var _this = this; _super.call(this);
2771
+ function Tag(input) {
2772
+ var _this = _super.call(this, input) || this;
2699
2773
  _this.seal();
2700
2774
  return _this;
2701
2775
  }
@@ -2709,6 +2783,9 @@ var Tag = /** @class */ (function (_super) {
2709
2783
  $.node = node;
2710
2784
  $.parent.appendNode(node);
2711
2785
  };
2786
+ Tag.prototype.compose = function (input) {
2787
+ input.slot && input.slot(this);
2788
+ };
2712
2789
  Tag.prototype.findFirstChild = function () {
2713
2790
  return this.$.unmounted ? null : this.$.node;
2714
2791
  };
@@ -2726,8 +2803,7 @@ var Tag = /** @class */ (function (_super) {
2726
2803
  }
2727
2804
  };
2728
2805
  Tag.prototype.appendNode = function (node) {
2729
- var $ = this.$;
2730
- $.app.run.appendChild($.node, node);
2806
+ this.$.node.appendChild(node);
2731
2807
  };
2732
2808
  /**
2733
2809
  * Mount/Unmount a node
@@ -2763,18 +2839,20 @@ var Tag = /** @class */ (function (_super) {
2763
2839
  */
2764
2840
  var Extension = /** @class */ (function (_super) {
2765
2841
  __extends(Extension, _super);
2766
- function Extension($) {
2767
- var _this = _super.call(this, $) || this;
2768
- _this.seal();
2769
- return _this;
2842
+ function Extension() {
2843
+ return _super !== null && _super.apply(this, arguments) || this;
2770
2844
  }
2771
2845
  Extension.prototype.preinit = function (app, parent) {
2772
- if (parent instanceof INode) {
2773
- var $ = this.$;
2774
- $.preinit(app, parent);
2775
- $.node = parent.node;
2846
+ var $ = this.$;
2847
+ var it = parent;
2848
+ while (it && !(it instanceof INode)) {
2849
+ it = it.parent;
2776
2850
  }
2777
- else {
2851
+ if (it && it instanceof INode) {
2852
+ $.node = it.node;
2853
+ }
2854
+ $.preinit(app, parent);
2855
+ if (!it) {
2778
2856
  throw userError("A extension node can be encapsulated only in a tag/extension/component", "virtual-dom");
2779
2857
  }
2780
2858
  };
@@ -2792,12 +2870,10 @@ var Extension = /** @class */ (function (_super) {
2792
2870
  var Component = /** @class */ (function (_super) {
2793
2871
  __extends(Component, _super);
2794
2872
  function Component() {
2795
- var _this = this; _super.call(this);
2796
- _this.seal();
2797
- return _this;
2873
+ return _super !== null && _super.apply(this, arguments) || this;
2798
2874
  }
2799
- Component.prototype.mounted = function () {
2800
- _super.prototype.mounted.call(this);
2875
+ Component.prototype.ready = function () {
2876
+ _super.prototype.ready.call(this);
2801
2877
  if (this.children.size !== 1) {
2802
2878
  throw userError("Component must have a child only", "dom-error");
2803
2879
  }
@@ -2825,6 +2901,11 @@ var SwitchedNodePrivate = /** @class */ (function (_super) {
2825
2901
  __extends(SwitchedNodePrivate, _super);
2826
2902
  function SwitchedNodePrivate() {
2827
2903
  var _this = this; _super.call(this);
2904
+ /**
2905
+ * Array of possible cases
2906
+ * @type {Array<{cond : IValue<boolean>, cb : function(Fragment)}>}
2907
+ */
2908
+ _this.cases = [];
2828
2909
  _this.seal();
2829
2910
  return _this;
2830
2911
  }
@@ -2851,7 +2932,7 @@ var SwitchedNode = /** @class */ (function (_super) {
2851
2932
  * Constructs a switch node and define a sync function
2852
2933
  */
2853
2934
  function SwitchedNode() {
2854
- var _this = _super.call(this, new SwitchedNodePrivate) || this;
2935
+ var _this = _super.call(this, {}, new SwitchedNodePrivate) || this;
2855
2936
  _this.$.sync = function () {
2856
2937
  var $ = _this.$;
2857
2938
  var i = 0;
@@ -2879,20 +2960,17 @@ var SwitchedNode = /** @class */ (function (_super) {
2879
2960
  _this.seal();
2880
2961
  return _this;
2881
2962
  }
2882
- /**
2883
- * Set up switch cases
2884
- * @param cases {{ cond : IValue, cb : function(Fragment) }}
2885
- */
2886
- SwitchedNode.prototype.setCases = function (cases) {
2887
- var $ = this.$;
2888
- $.cases = __spreadArray([], cases, true);
2963
+ SwitchedNode.prototype.addCase = function (case_) {
2964
+ this.$.cases.push(case_);
2965
+ case_.cond.on(this.$.sync);
2966
+ this.$.sync();
2889
2967
  };
2890
2968
  /**
2891
2969
  * Creates a child node
2892
2970
  * @param cb {function(Fragment)} Call-back
2893
2971
  */
2894
2972
  SwitchedNode.prototype.createChild = function (cb) {
2895
- var node = new Fragment();
2973
+ var node = new Fragment({});
2896
2974
  node.preinit(this.$.app, this);
2897
2975
  node.init();
2898
2976
  this.lastChild = node;
@@ -2915,6 +2993,7 @@ var SwitchedNode = /** @class */ (function (_super) {
2915
2993
  };
2916
2994
  return SwitchedNode;
2917
2995
  }(Fragment));
2996
+
2918
2997
  /**
2919
2998
  * The private part of a text node
2920
2999
  */
@@ -2958,7 +3037,7 @@ var DebugPrivate = /** @class */ (function (_super) {
2958
3037
  var DebugNode = /** @class */ (function (_super) {
2959
3038
  __extends(DebugNode, _super);
2960
3039
  function DebugNode() {
2961
- var _this = this; _super.call(this);
3040
+ var _this = _super.call(this, {}) || this;
2962
3041
  /**
2963
3042
  * private data
2964
3043
  * @type {DebugNode}
@@ -2995,6 +3074,7 @@ window.Tag = Tag;
2995
3074
  window.Extension = Extension;
2996
3075
  window.Component = Component;
2997
3076
  window.SwitchedNodePrivate = SwitchedNodePrivate;
3077
+ window.SwitchedNode = SwitchedNode;
2998
3078
  window.DebugPrivate = DebugPrivate;
2999
3079
  window.DebugNode = DebugNode;
3000
3080
 
@@ -3007,12 +3087,12 @@ window.DebugNode = DebugNode;
3007
3087
  var AppNode = /** @class */ (function (_super) {
3008
3088
  __extends(AppNode, _super);
3009
3089
  /**
3010
- * @param options {Object} Application options
3090
+ * @param input
3011
3091
  */
3012
- function AppNode(options) {
3013
- var _this = this; _super.call(this);
3014
- _this.run = (options === null || options === void 0 ? void 0 : options.executor) || ((options === null || options === void 0 ? void 0 : options.freezeUi) === false ? timeoutExecutor : instantExecutor);
3015
- _this.debugUi = (options === null || options === void 0 ? void 0 : options.debugUi) || false;
3092
+ function AppNode(input) {
3093
+ var _this = _super.call(this, input) || this;
3094
+ _this.debugUi = input.debugUi || false;
3095
+ _this.seal();
3016
3096
  return _this;
3017
3097
  }
3018
3098
  return AppNode;
@@ -3028,25 +3108,40 @@ var App = /** @class */ (function (_super) {
3028
3108
  /**
3029
3109
  * Constructs an app node
3030
3110
  * @param node {Element} The root of application
3031
- * @param options {Object} Application options
3111
+ * @param input
3032
3112
  */
3033
- function App(node, options) {
3034
- var _this = _super.call(this, options) || this;
3113
+ function App(node, input) {
3114
+ var _this = _super.call(this, input) || this;
3035
3115
  _this.$.node = node;
3036
3116
  _this.preinit(_this, _this);
3117
+ _this.init();
3037
3118
  _this.seal();
3038
3119
  return _this;
3039
3120
  }
3040
3121
  App.prototype.appendNode = function (node) {
3041
- var $ = this.$;
3042
- this.run.appendChild($.node, node);
3122
+ this.$.node.appendChild(node);
3043
3123
  };
3044
3124
  return App;
3045
3125
  }(AppNode));
3046
3126
 
3127
+ var Portal = /** @class */ (function (_super) {
3128
+ __extends(Portal, _super);
3129
+ function Portal(input) {
3130
+ var _this = _super.call(this, input) || this;
3131
+ _this.$.node = input.node;
3132
+ _this.seal();
3133
+ return _this;
3134
+ }
3135
+ Portal.prototype.appendNode = function (node) {
3136
+ this.$.node.appendChild(node);
3137
+ };
3138
+ return Portal;
3139
+ }(AppNode));
3140
+
3047
3141
 
3048
3142
  window.AppNode = AppNode;
3049
3143
  window.App = App;
3144
+ window.Portal = Portal;
3050
3145
 
3051
3146
  // ./lib-es5/node/interceptor.js
3052
3147
  /**
@@ -3159,10 +3254,15 @@ var AttributeBinding = /** @class */ (function (_super) {
3159
3254
  var _this = _super.call(this, value) || this;
3160
3255
  _this.init(function (value) {
3161
3256
  if (value) {
3162
- node.app.run.setAttribute(node.node, name, value);
3257
+ if (typeof value === 'boolean') {
3258
+ node.node.setAttribute(name, "");
3259
+ }
3260
+ else {
3261
+ node.node.setAttribute(name, "".concat(value));
3262
+ }
3163
3263
  }
3164
3264
  else {
3165
- node.app.run.removeAttribute(node.node, name);
3265
+ node.node.removeAttribute(name);
3166
3266
  }
3167
3267
  });
3168
3268
  _this.seal();
@@ -3192,7 +3292,7 @@ var StyleBinding = /** @class */ (function (_super) {
3192
3292
  var _this = _super.call(this, value) || this;
3193
3293
  _this.init(function (value) {
3194
3294
  if (node.node instanceof HTMLElement) {
3195
- node.app.run.setStyle(node.node, name, value);
3295
+ node.node.style.setProperty(name, value);
3196
3296
  }
3197
3297
  });
3198
3298
  _this.seal();
@@ -3206,10 +3306,10 @@ window.StyleBinding = StyleBinding;
3206
3306
 
3207
3307
  // ./lib-es5/binding/class.js
3208
3308
  function addClass(node, cl) {
3209
- node.app.run.addClass(node.node, cl);
3309
+ node.node.classList.add(cl);
3210
3310
  }
3211
3311
  function removeClass(node, cl) {
3212
- node.app.run.removeClass(node.node, cl);
3312
+ node.node.classList.remove(cl);
3213
3313
  }
3214
3314
  var StaticClassBinding = /** @class */ (function (_super) {
3215
3315
  __extends(StaticClassBinding, _super);
@@ -3291,19 +3391,16 @@ var RepeatNodePrivate = /** @class */ (function (_super) {
3291
3391
  */
3292
3392
  var RepeatNode = /** @class */ (function (_super) {
3293
3393
  __extends(RepeatNode, _super);
3294
- function RepeatNode($) {
3295
- var _this = _super.call(this, $ || new RepeatNodePrivate) || this;
3394
+ function RepeatNode(input, $) {
3395
+ var _this = _super.call(this, input, $) || this;
3296
3396
  /**
3297
3397
  * If false will use timeout executor, otherwise the app executor
3298
3398
  */
3299
3399
  _this.freezeUi = true;
3300
- _this.slot = new Slot;
3301
3400
  return _this;
3302
3401
  }
3303
- RepeatNode.prototype.createChild = function (id, item, before) {
3304
- // TODO: Refactor: remove @ts-ignore
3305
- var _this = this;
3306
- var node = new Fragment();
3402
+ RepeatNode.prototype.createChild = function (opts, id, item, before) {
3403
+ var node = new Fragment({});
3307
3404
  this.destroyChild(id, item);
3308
3405
  if (before) {
3309
3406
  this.children.add(node);
@@ -3319,16 +3416,8 @@ var RepeatNode = /** @class */ (function (_super) {
3319
3416
  this.lastChild = node;
3320
3417
  node.preinit(this.$.app, this);
3321
3418
  node.init();
3322
- var callback = function () {
3323
- _this.slot.release(node, item, id);
3324
- node.ready();
3325
- };
3326
- if (this.freezeUi) {
3327
- this.$.app.run.callCallback(callback);
3328
- }
3329
- else {
3330
- timeoutExecutor.callCallback(callback);
3331
- }
3419
+ opts.slot && opts.slot(node, item, id);
3420
+ node.ready();
3332
3421
  this.$.nodes.set(id, node);
3333
3422
  };
3334
3423
  RepeatNode.prototype.destroyChild = function (id, item) {
@@ -3446,35 +3535,24 @@ var BaseViewPrivate = /** @class */ (function (_super) {
3446
3535
  */
3447
3536
  var BaseView = /** @class */ (function (_super) {
3448
3537
  __extends(BaseView, _super);
3449
- function BaseView($1) {
3450
- var _this = _super.call(this, $1 || new BaseViewPrivate) || this;
3451
- var $ = _this.$;
3538
+ function BaseView(input, $) {
3539
+ return _super.call(this, input, $ || new BaseViewPrivate) || this;
3540
+ }
3541
+ BaseView.prototype.compose = function (input) {
3542
+ var _this = this;
3543
+ var $ = this.$;
3452
3544
  $.addHandler = function (id, item) {
3453
- _this.createChild(id, item);
3545
+ _this.createChild(input, id, item);
3454
3546
  };
3455
3547
  $.removeHandler = function (id, item) {
3456
3548
  _this.destroyChild(id, item);
3457
3549
  };
3458
- _this.seal();
3459
- return _this;
3460
- }
3461
- /**
3462
- * Handle ready event
3463
- */
3464
- BaseView.prototype.ready = function () {
3465
- var $ = this.$;
3466
- this.model.listener.onAdd($.addHandler);
3467
- this.model.listener.onRemove($.removeHandler);
3468
- _super.prototype.ready.call(this);
3469
- };
3470
- /**
3471
- * Handles destroy event
3472
- */
3473
- BaseView.prototype.destroy = function () {
3474
- var $ = this.$;
3475
- this.model.listener.offAdd($.addHandler);
3476
- this.model.listener.offRemove($.removeHandler);
3477
- _super.prototype.destroy.call(this);
3550
+ input.model.listener.onAdd($.addHandler);
3551
+ input.model.listener.onRemove($.removeHandler);
3552
+ this.runOnDestroy(function () {
3553
+ input.model.listener.offAdd($.addHandler);
3554
+ input.model.listener.offRemove($.removeHandler);
3555
+ });
3478
3556
  };
3479
3557
  return BaseView;
3480
3558
  }(RepeatNode));
@@ -3491,20 +3569,18 @@ window.BaseView = BaseView;
3491
3569
  */
3492
3570
  var ArrayView = /** @class */ (function (_super) {
3493
3571
  __extends(ArrayView, _super);
3494
- function ArrayView(model) {
3495
- var _this = this; _super.call(this);
3496
- _this.model = model;
3497
- return _this;
3572
+ function ArrayView() {
3573
+ return _super !== null && _super.apply(this, arguments) || this;
3498
3574
  }
3499
- ArrayView.prototype.createChild = function (id, item, before) {
3500
- _super.prototype.createChild.call(this, item, item, before || this.$.nodes.get(id));
3575
+ ArrayView.prototype.createChild = function (input, id, item, before) {
3576
+ _super.prototype.createChild.call(this, input, item, item, before || this.$.nodes.get(id));
3501
3577
  };
3502
- ArrayView.prototype.ready = function () {
3578
+ ArrayView.prototype.compose = function (input) {
3503
3579
  var _this = this;
3504
- this.model.forEach(function (item) {
3505
- _this.createChild(item, item);
3580
+ _super.prototype.compose.call(this, input);
3581
+ input.model.forEach(function (item) {
3582
+ _this.createChild(input, item, item);
3506
3583
  });
3507
- _super.prototype.ready.call(this);
3508
3584
  };
3509
3585
  return ArrayView;
3510
3586
  }(BaseView));
@@ -3521,24 +3597,19 @@ window.ArrayView = ArrayView;
3521
3597
  var Watch = /** @class */ (function (_super) {
3522
3598
  __extends(Watch, _super);
3523
3599
  function Watch() {
3524
- var _this = this; _super.call(this);
3525
- _this.slot = new Slot;
3526
- _this.model = _this.ref(null);
3527
- _this.seal();
3528
- return _this;
3600
+ return _super !== null && _super.apply(this, arguments) || this;
3529
3601
  }
3530
- Watch.prototype.createWatchers = function () {
3602
+ Watch.prototype.compose = function (input) {
3531
3603
  var _this = this;
3532
3604
  this.watch(function (value) {
3533
3605
  _this.children.forEach(function (child) {
3534
3606
  child.destroy();
3535
3607
  });
3536
3608
  _this.children.clear();
3537
- _this.slot.release(_this, value);
3538
- }, this.model);
3539
- };
3540
- Watch.prototype.compose = function () {
3541
- this.slot.release(this, this.model.$);
3609
+ _this.lastChild = null;
3610
+ input.slot && input.slot(_this, value);
3611
+ }, input.model);
3612
+ input.slot(this, input.model.$);
3542
3613
  };
3543
3614
  return Watch;
3544
3615
  }(Fragment));
@@ -3554,15 +3625,14 @@ window.Watch = Watch;
3554
3625
  */
3555
3626
  var ObjectView = /** @class */ (function (_super) {
3556
3627
  __extends(ObjectView, _super);
3557
- function ObjectView(model) {
3558
- var _this = this; _super.call(this);
3559
- _this.model = model;
3560
- return _this;
3628
+ function ObjectView() {
3629
+ return _super !== null && _super.apply(this, arguments) || this;
3561
3630
  }
3562
- ObjectView.prototype.ready = function () {
3563
- var obj = this.model;
3631
+ ObjectView.prototype.compose = function (input) {
3632
+ _super.prototype.compose.call(this, input);
3633
+ var obj = input.model.proxy();
3564
3634
  for (var key in obj) {
3565
- this.createChild(key, obj[key]);
3635
+ this.createChild(input, key, obj[key]);
3566
3636
  }
3567
3637
  _super.prototype.ready.call(this);
3568
3638
  };
@@ -3580,18 +3650,15 @@ window.ObjectView = ObjectView;
3580
3650
  */
3581
3651
  var MapView = /** @class */ (function (_super) {
3582
3652
  __extends(MapView, _super);
3583
- function MapView(model) {
3584
- var _this = this; _super.call(this);
3585
- _this.model = model;
3586
- return _this;
3653
+ function MapView() {
3654
+ return _super !== null && _super.apply(this, arguments) || this;
3587
3655
  }
3588
- MapView.prototype.ready = function () {
3656
+ MapView.prototype.compose = function (input) {
3589
3657
  var _this = this;
3590
- var map = this.model;
3591
- map.forEach(function (value, key) {
3592
- _this.createChild(key, value);
3658
+ _super.prototype.compose.call(this, input);
3659
+ input.model.forEach(function (value, key) {
3660
+ _this.createChild(input, key, value);
3593
3661
  });
3594
- _super.prototype.ready.call(this);
3595
3662
  };
3596
3663
  return MapView;
3597
3664
  }(BaseView));
@@ -3607,21 +3674,16 @@ window.MapView = MapView;
3607
3674
  */
3608
3675
  var SetView = /** @class */ (function (_super) {
3609
3676
  __extends(SetView, _super);
3610
- function SetView(model) {
3611
- var _this = this; _super.call(this);
3612
- _this.model = model;
3613
- return _this;
3677
+ function SetView() {
3678
+ return _super !== null && _super.apply(this, arguments) || this;
3614
3679
  }
3615
- SetView.prototype.ready = function () {
3680
+ SetView.prototype.compose = function (input) {
3616
3681
  var _this = this;
3617
- var $ = this.$;
3618
- var set = this.model;
3682
+ _super.prototype.compose.call(this, input);
3683
+ var set = input.model;
3619
3684
  set.forEach(function (item) {
3620
- $.app.run.callCallback(function () {
3621
- _this.createChild(item, item);
3622
- });
3685
+ _this.createChild(input, item, item);
3623
3686
  });
3624
- _super.prototype.ready.call(this);
3625
3687
  };
3626
3688
  return SetView;
3627
3689
  }(BaseView));