targetj 1.0.143 → 1.0.145

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.
package/README.md CHANGED
@@ -146,11 +146,13 @@ App(new TModel('quickExample', {
146
146
 
147
147
  ### Loading API Example
148
148
 
149
- In this example, we will load two separate users, and once both APIs return a result, we will display their names and flash the background. All targets without a prefix `'_'` will be executed in the order they appear in the code. Targets with the prefix `'_'` are inactive and must be activated externally. Target names with the suffix `'$'` indicate that they will be activated when the previous target is executed. This allows these targets to form a functional execution pipeline.
149
+ In this example, we load two separate users, and once both API calls return results, we display their names and briefly flash the background.
150
150
 
151
- The `'html'` target initializes the text content of the `'div'` to `'loading'`. The `div` is the default element if no `baseElement` target is specified. Then, the `loadUser1` and `loadUser2` targets are executed. If the API call for `loadUser2` returns a result before `loadUser1`, `loadUser2` will be executed again. However, it will fetch the result from the loader cache because we specified the fourth argument in the `fetch()` function. This means another API call will not be made, but it will still activate the `displayName` target again, ensuring that both users' names are displayed without any race conditions.
151
+ All targets without a prefix `_` execute in the order they appear in the code. Targets prefixed with `_` are inactive by default and must be activated externally. Target names ending with `$` indicate that they will activate when the previous target completes, allowing them to form a functional execution pipeline.
152
152
 
153
- The execution pipeline will then continue, expanding the width and height while morphing the background from yellow to purple over 15 steps, with 15-millisecond pauses between them..
153
+ The `html` target initializes the text content of the `div` to `"loading"`. If no `baseElement` target is specified, the `div` is the default element. Then, the `loadUsers` target executes. Once both API results are retrieved, the `displayName` target runs, accessing the results in an array ordered by the sequence in which the APIs were called.
154
+
155
+ The execution pipeline then continues, gradually expanding the width and height while transitioning the background color from yellow to purple over 15 steps, with 15-millisecond pauses between each step.
154
156
 
155
157
  ![first example](https://targetjs.io/img/loadingExample6.gif)
156
158
 
@@ -159,19 +161,13 @@ import { App, TModel, getLoader } from "targetj";
159
161
 
160
162
  App(new TModel('apiCall', {
161
163
  html: 'Loading...',
162
- loadUser1() {
163
- getLoader().fetch(this, 'https://targetjs.io/api/randomUser', { id: 'user0' });
164
+ loadUsers() {
165
+ getLoader().fetch(this, "https://targetjs.io/api/randomUser", { id: "user0" });
166
+ getLoader().fetch(this, "https://targetjs.io/api/randomUser", { id: "user1" });
164
167
  },
165
- loadUser2$() {
166
- getLoader().fetch(this, 'https://targetjs.io/api/randomUser', { id: 'user1' }, 'user1');
167
- },
168
- _displayName$: {
169
- value() {
170
- this.setTarget('html', `${this.val('loadUser1').name} ${this.val('loadUser2').name}`);
171
- },
172
- enabledOn() {
173
- return this.val('loadUser1') && this.val('loadUser2');
174
- }
168
+ _displayName$() {
169
+ const [ user0, user1 ] = this.prevTargetValue;
170
+ this.setTarget("html", `${user0.name} ${user1.name}`);
175
171
  },
176
172
  _width$: 200,
177
173
  _height$: 200,
@@ -361,10 +357,16 @@ This method is invoked only after the final step of updating the actual value is
361
357
  13. **initialValue**
362
358
  This is only property. It defines the initial value of the actual value.
363
359
 
364
- 14. Postfix **$** to the target name
365
- Targets with a `$` postfix in their names indicate that they will be activated when the preceding target is executed or updated.
360
+ 14. **activateNextTarget**
361
+ This is a string property that specifies the target to be activated when this target executes. If the name ends with `$`, the target will only activate after the current target and all of its imperative targets have completed.
366
362
 
367
- 15. **this.prevTargetValue** and **this.isPrevTargetUpdated()**
363
+ 15. **Postfix `$` to the target name**
364
+ A target name ending with `$` indicates that it will be activated when the preceding target is executed or updated. It works similarly to `activateNextTarget`, but it only applies to the target that appears next to it.
365
+
366
+ 16. **Postfix `$$` to the target name**
367
+ A target name ending with `$$` indicates that it will be activated only after the preceding target and all of its imperative targets have completed. It works similarly to `activateNextTarget` when it ends with `$`, but it applies only to the target immediately following it.
368
+
369
+ 17. **this.prevTargetValue** and **this.isPrevTargetUpdated()**
368
370
  `this.prevTargetValue` holds the value of the previous target, while `this.isPrevTargetUpdated()` returns `true` if the previous target has been updated. This method is useful when a target is activated externally, such as by a user event, rather than by the preceding target.
369
371
 
370
372
  ---
@@ -545,18 +545,18 @@ var BaseModel = exports.BaseModel = /*#__PURE__*/function () {
545
545
  }
546
546
  }, {
547
547
  key: "setTarget",
548
- value: function setTarget(key, value, steps, interval, easing, originalTargetName) {
548
+ value: function setTarget(key, value, steps, interval, easing) {
549
549
  if (_typeof(key) === 'object' && key !== null) {
550
550
  var _ref3 = [key, value, steps, interval, easing];
551
551
  value = _ref3[0];
552
552
  steps = _ref3[1];
553
553
  interval = _ref3[2];
554
554
  easing = _ref3[3];
555
- originalTargetName = _ref3[4];
556
555
  key = '';
557
556
  }
558
- originalTargetName = originalTargetName || this.key;
559
- _TargetExecutor.TargetExecutor.executeImperativeTarget(this, key, value, steps, interval, easing, originalTargetName);
557
+ var originalTargetName = _TargetUtil.TargetUtil.currentTargetName;
558
+ var originalTModel = _TargetUtil.TargetUtil.currentTModel;
559
+ _TargetExecutor.TargetExecutor.executeImperativeTarget(this, key, value, steps, interval, easing, originalTargetName, originalTModel);
560
560
  return this;
561
561
  }
562
562
  }, {
@@ -609,8 +609,8 @@ var EventListener = exports.EventListener = /*#__PURE__*/function () {
609
609
  }, {
610
610
  key: "resizeRoot",
611
611
  value: function resizeRoot() {
612
- (0, _App.tRoot)().val('width', (0, _App.tRoot)().targets.width());
613
- (0, _App.tRoot)().val('height', (0, _App.tRoot)().targets.height());
612
+ (0, _App.tRoot)().val('width', (0, _App.tRoot)().targets.width.value());
613
+ (0, _App.tRoot)().val('height', (0, _App.tRoot)().targets.height.value());
614
614
  (0, _App.tRoot)().setActualValueLastUpdate('width');
615
615
  (0, _App.tRoot)().setActualValueLastUpdate('height');
616
616
  }
@@ -279,18 +279,16 @@ var LocationManager = exports.LocationManager = /*#__PURE__*/function () {
279
279
  var originalTarget = (0, _App.getEvents)().getEventTarget();
280
280
  eventTargets.forEach(function (targetName) {
281
281
  var target = tmodel.targets[targetName];
282
- if (typeof target === 'function') {
283
- target.call(tmodel, originalTarget);
284
- } else if (Array.isArray(target)) {
285
- target.forEach(function (t) {
286
- return _TargetUtil.TargetUtil.activateSingleTarget(tmodel, t);
287
- });
288
- } else if (_typeof(target) === 'object') {
289
- if (tmodel.isTargetEnabled(targetName) && typeof target.value === 'function') {
282
+ if (tmodel.isTargetEnabled(targetName)) {
283
+ if (typeof target.value === 'function') {
290
284
  target.value.call(tmodel, originalTarget);
285
+ } else if (Array.isArray(target.value)) {
286
+ target.value.forEach(function (t) {
287
+ return _TargetUtil.TargetUtil.activateSingleTarget(tmodel, t);
288
+ });
289
+ } else {
290
+ _TargetUtil.TargetUtil.activateSingleTarget(tmodel, target.value);
291
291
  }
292
- } else {
293
- _TargetUtil.TargetUtil.activateSingleTarget(tmodel, target);
294
292
  }
295
293
  });
296
294
  }
package/build/TModel.js CHANGED
@@ -116,6 +116,13 @@ var TModel = exports.TModel = /*#__PURE__*/function (_BaseModel) {
116
116
  index: index,
117
117
  child: child
118
118
  });
119
+ child.parent = this;
120
+ if (child.updatingTargetList.length > 0) {
121
+ this.addToUpdatingChildren(child);
122
+ }
123
+ if (child.activeTargetList.length > 0) {
124
+ this.addToActiveChildren(child);
125
+ }
119
126
  child.activate();
120
127
  return this;
121
128
  }
@@ -166,7 +173,6 @@ var TModel = exports.TModel = /*#__PURE__*/function (_BaseModel) {
166
173
  if (_this2.allChildrenMap[child.oid]) {
167
174
  return;
168
175
  }
169
- child.parent = _this2;
170
176
  if (!_TUtil.TUtil.isDefined(child.val('canDeleteDom')) && _this2.val('canDeleteDom') === false) {
171
177
  child.val('canDeleteDom', false);
172
178
  }
@@ -37,21 +37,37 @@ var TargetExecutor = exports.TargetExecutor = /*#__PURE__*/function () {
37
37
  }
38
38
  }, {
39
39
  key: "executeImperativeTarget",
40
- value: function executeImperativeTarget(tmodel, key, value, steps, interval, easing, originalTargetName) {
40
+ value: function executeImperativeTarget(tmodel, key, value, steps, interval, easing, originalTargetName, originalTModel) {
41
41
  tmodel.targetValues[key] = tmodel.targetValues[key] || _TargetUtil.TargetUtil.emptyValue();
42
42
  var targetValue = tmodel.targetValues[key];
43
43
  targetValue.isImperative = true;
44
44
  targetValue.originalTargetName = originalTargetName;
45
+ targetValue.originalTModel = originalTModel;
45
46
  if (_TargetUtil.TargetUtil.isListTarget(value)) {
46
47
  TargetExecutor.assignListTarget(targetValue, value.list, value.list[0], steps, interval, easing);
47
48
  } else if (_TargetUtil.TargetUtil.isObjectTarget(key, value)) {
48
49
  var completeValue = _TargetUtil.TargetUtil.cssFunctionMap[key] ? _objectSpread(_objectSpread({}, _TargetUtil.TargetUtil.cssFunctionMap[key]), value) : value;
49
50
  Object.keys(completeValue).forEach(function (objectKey) {
50
- TargetExecutor.executeImperativeTarget(tmodel, objectKey, completeValue[objectKey], steps, interval, easing, originalTargetName);
51
+ var newValue = completeValue[objectKey];
52
+ if (_typeof(newValue) === 'object' && !_TargetUtil.TargetUtil.isListTarget(newValue)) {
53
+ var valueArray = _TargetUtil.TargetUtil.getValueStepsCycles(tmodel, completeValue[objectKey], key);
54
+ newValue = valueArray[0];
55
+ steps = _TUtil.TUtil.isDefined(valueArray[1]) ? valueArray[1] : steps;
56
+ interval = _TUtil.TUtil.isDefined(valueArray[2]) ? valueArray[2] : interval;
57
+ }
58
+ TargetExecutor.executeImperativeTarget(tmodel, objectKey, newValue, steps, interval, easing, originalTargetName, originalTModel);
51
59
  });
52
60
  } else {
53
- TargetExecutor.assignSingleTarget(targetValue, value, undefined, steps, 0, interval, easing);
54
- targetValue.step = 0;
61
+ if (_typeof(value) === 'object' && !_TargetUtil.TargetUtil.isListTarget(value)) {
62
+ var valueArray = _TargetUtil.TargetUtil.getValueStepsCycles(tmodel, value, key);
63
+ value = valueArray[0];
64
+ steps = _TUtil.TUtil.isDefined(valueArray[1]) ? valueArray[1] : steps;
65
+ interval = _TUtil.TUtil.isDefined(valueArray[2]) ? valueArray[2] : interval;
66
+ TargetExecutor.executeImperativeTarget(tmodel, key, value, steps, interval, easing, originalTargetName, originalTModel);
67
+ } else {
68
+ TargetExecutor.assignSingleTarget(targetValue, value, undefined, steps, 0, interval, easing);
69
+ targetValue.step = 0;
70
+ }
55
71
  }
56
72
  TargetExecutor.updateTarget(tmodel, targetValue, key);
57
73
  }
@@ -121,7 +137,7 @@ var TargetExecutor = exports.TargetExecutor = /*#__PURE__*/function () {
121
137
  key: "resolveTargetValue",
122
138
  value: function resolveTargetValue(tmodel, key) {
123
139
  var targetInitial = !tmodel.targetValues[key] && _TUtil.TUtil.isDefined(tmodel.targets[key].initialValue) ? tmodel.targets[key].initialValue : undefined;
124
- var valueArray = _TargetUtil.TargetUtil.getValueStepsCycles(tmodel, key);
140
+ var valueArray = _TargetUtil.TargetUtil.getValueStepsCycles(tmodel, tmodel.targets[key], key);
125
141
  var newValue = valueArray[0];
126
142
  var newSteps = valueArray[1] || 0;
127
143
  var newInterval = valueArray[2] || 0;
@@ -235,7 +235,6 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
235
235
  originalTarget.onImperativeEnd.call(originalTModel, key, originalTModel.val(key));
236
236
  originalTModel.setTargetMethodName(originalTargetName, 'onImperativeEnd');
237
237
  }
238
- _TargetUtil.TargetUtil.shouldActivateNextTargetOnEnd(tmodel, originalTargetName);
239
238
  } else {
240
239
  if (!targetValue.valueList && tmodel.getTargetCycle(key) < tmodel.getTargetCycles(key)) {
241
240
  tmodel.incrementTargetCycle(key, tmodel.getTargetCycle(key));
@@ -249,6 +248,7 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
249
248
  }
250
249
  }
251
250
  tmodel.updateTargetStatus(key);
251
+ _TargetUtil.TargetUtil.shouldActivateNextTarget(tmodel, key, true);
252
252
  (0, _App.getRunScheduler)().schedule(scheduleTime, "".concat(tmodel.oid, "---").concat(key, "-").concat(step, "/").concat(steps, "-").concat(cycle, "-").concat(interval));
253
253
  }
254
254
  }]);
@@ -107,72 +107,66 @@ var TargetUtil = exports.TargetUtil = /*#__PURE__*/function () {
107
107
  return currentPrevUpdateTime !== lastPrevUpdateTime;
108
108
  };
109
109
  var doesNextTargetUsePrevValue = nextKey && nextKey.endsWith('$') ? true : false;
110
+ if (_typeof(target) !== 'object' || Array.isArray(target)) {
111
+ tmodel.targets[key] = {
112
+ value: target
113
+ };
114
+ target = tmodel.targets[key];
115
+ target.parentTargetName = TargetUtil.currentTargetName;
116
+ target.parentTModel = TargetUtil.currentTModel;
117
+ }
110
118
  if (doesNextTargetUsePrevValue) {
111
- if (_typeof(target) === 'object' && !Array.isArray(target)) {
112
- target.activateNextTarget = nextKey.slice(0, -1);
113
- } else {
114
- tmodel.targets[key] = {
115
- value: target,
116
- activateNextTarget: nextKey.slice(0, -1)
119
+ target.activateNextTarget = nextKey.slice(0, -1);
120
+ }
121
+ var stepPattern = /^on[A-Za-z]+Step$/;
122
+ var endPattern = /^on[A-Za-z]+End$/;
123
+ var methods = ['value', 'enabledOn', 'onStepsEnd', 'onValueChange', 'loop', 'onImperativeEnd', 'onImperativeStep', 'onSuccess', 'onError'];
124
+ Object.keys(target).forEach(function (method) {
125
+ if (typeof target[method] === 'function' && (methods.includes(method) || stepPattern.test(method) || endPattern.test(method))) {
126
+ var originalMethod = target[method];
127
+ target[method] = function () {
128
+ var _getPrevUpdateTime;
129
+ TargetUtil.currentTargetName = TargetUtil.getTargetName(key);
130
+ TargetUtil.currentTModel = tmodel;
131
+ this.key = TargetUtil.getTargetName(key);
132
+ this.prevTargetValue = getPrevValue();
133
+ this.isPrevTargetUpdated = isPrevTargetUpdated;
134
+ var result = originalMethod.apply(this, arguments);
135
+ lastPrevUpdateTime = (_getPrevUpdateTime = getPrevUpdateTime()) !== null && _getPrevUpdateTime !== void 0 ? _getPrevUpdateTime : lastPrevUpdateTime;
136
+ return result;
117
137
  };
118
- target = tmodel.targets[key];
119
138
  }
120
- }
121
- if (_typeof(target) === 'object') {
122
- var stepPattern = /^on[A-Za-z]+Step$/;
123
- var endPattern = /^on[A-Za-z]+End$/;
124
- var methods = ['value', 'enabledOn', 'onStepsEnd', 'onValueChange', 'loop', 'onImperativeEnd', 'onImperativeStep', 'onSuccess', 'onError'];
125
- Object.keys(target).forEach(function (method) {
126
- if (typeof target[method] === 'function' && (methods.includes(method) || stepPattern.test(method) || endPattern.test(method))) {
127
- var originalMethod = target[method];
128
- target[method] = function () {
129
- var _getPrevUpdateTime;
130
- this.key = TargetUtil.getTargetName(key);
131
- this.prevTargetValue = getPrevValue();
132
- this.isPrevTargetUpdated = isPrevTargetUpdated;
133
- var result = originalMethod.apply(this, arguments);
134
- lastPrevUpdateTime = (_getPrevUpdateTime = getPrevUpdateTime()) !== null && _getPrevUpdateTime !== void 0 ? _getPrevUpdateTime : lastPrevUpdateTime;
135
- return result;
136
- };
137
- }
138
- });
139
- } else if (typeof target === 'function') {
140
- var originalFunction = target;
141
- tmodel.targets[key] = function () {
142
- var _getPrevUpdateTime2;
143
- this.key = TargetUtil.getTargetName(key);
144
- this.prevTargetValue = getPrevValue();
145
- this.isPrevTargetUpdated = isPrevTargetUpdated;
146
- var result = originalFunction.apply(this, arguments);
147
- lastPrevUpdateTime = (_getPrevUpdateTime2 = getPrevUpdateTime()) !== null && _getPrevUpdateTime2 !== void 0 ? _getPrevUpdateTime2 : lastPrevUpdateTime;
148
- return result;
149
- };
150
- }
139
+ });
151
140
  }
152
141
  }, {
153
142
  key: "shouldActivateNextTarget",
154
143
  value: function shouldActivateNextTarget(tmodel, key) {
155
- var _tmodel$targets$key;
156
- var target = (_tmodel$targets$key = tmodel.targets[key]) === null || _tmodel$targets$key === void 0 ? void 0 : _tmodel$targets$key.activateNextTarget;
157
- if (!target) {
158
- return;
144
+ var isEndTrigger = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
145
+ var level = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
146
+ var isImperative = tmodel.isTargetImperative(key);
147
+ var target = tmodel.targets[key];
148
+ if (target) {
149
+ var targetName = target.activateNextTarget;
150
+ if (targetName && !isImperative) {
151
+ isEndTrigger = isEndTrigger || targetName.endsWith('$');
152
+ if (isEndTrigger) {
153
+ if ((tmodel.isTargetComplete(key) || tmodel.isTargetDone(key)) && !tmodel.hasUpdatingTargets(key) && !tmodel.hasUpdatingChildren() && !tmodel.hasActiveChildren()) {
154
+ TargetUtil.activateNextTargetIfEligible(tmodel, key, targetName);
155
+ }
156
+ } else {
157
+ TargetUtil.activateNextTargetIfEligible(tmodel, key, targetName);
158
+ }
159
+ return;
160
+ }
159
161
  }
160
- var isEndTrigger = target.endsWith('$');
161
162
  if (isEndTrigger) {
162
- TargetUtil.shouldActivateNextTargetOnEnd(tmodel, key);
163
- } else {
164
- TargetUtil.activateNextTargetIfEligible(tmodel, key, target);
165
- }
166
- }
167
- }, {
168
- key: "shouldActivateNextTargetOnEnd",
169
- value: function shouldActivateNextTargetOnEnd(tmodel, key) {
170
- var _tmodel$targets$key2;
171
- var target = (_tmodel$targets$key2 = tmodel.targets[key]) === null || _tmodel$targets$key2 === void 0 ? void 0 : _tmodel$targets$key2.activateNextTarget;
172
- if (target && target.endsWith('$') && tmodel.isTargetComplete(key) && !tmodel.hasUpdatingTargets(key)) {
173
- TargetUtil.activateNextTargetIfEligible(tmodel, key, target);
163
+ var targetValue = tmodel.targetValues[key];
164
+ if (isImperative && targetValue.originalTargetName && targetValue.originalTModel) {
165
+ TargetUtil.shouldActivateNextTarget(targetValue.originalTModel, targetValue.originalTargetName, true, level + 1);
166
+ } else if (!isImperative && target && target.parentTargetName && target.parentTModel) {
167
+ TargetUtil.shouldActivateNextTarget(target.parentTModel, target.parentTargetName, true, level + 1);
168
+ }
174
169
  }
175
- ;
176
170
  }
177
171
  }, {
178
172
  key: "activateNextTargetIfEligible",
@@ -204,13 +198,12 @@ var TargetUtil = exports.TargetUtil = /*#__PURE__*/function () {
204
198
  if (arr.length > 4 || arr.length === 0) {
205
199
  return false;
206
200
  }
207
- var result = arr.length >= 2;
208
201
  for (var i = 1; i < arr.length; i++) {
209
202
  if (typeof arr[i] !== 'number') {
210
203
  return false;
211
204
  }
212
205
  }
213
- return result && (typeof arr[0] === 'number' || TargetUtil.isListTarget(arr[0]) || typeof arr[0] === 'string');
206
+ return arr.length >= 2 && (typeof arr[0] === 'number' || TargetUtil.isListTarget(arr[0]) || typeof arr[0] === 'string');
214
207
  }
215
208
  }, {
216
209
  key: "isListTarget",
@@ -229,8 +222,7 @@ var TargetUtil = exports.TargetUtil = /*#__PURE__*/function () {
229
222
  }
230
223
  }, {
231
224
  key: "getValueStepsCycles",
232
- value: function getValueStepsCycles(tmodel, key) {
233
- var _target = tmodel.targets[key];
225
+ value: function getValueStepsCycles(tmodel, _target, key) {
234
226
  var valueOnly = _target && _target.valueOnly;
235
227
  var cycle = tmodel.getTargetCycle(key);
236
228
  var lastValue = tmodel.val(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "targetj",
3
- "version": "1.0.143",
3
+ "version": "1.0.145",
4
4
  "keywords": [
5
5
  "targetjs"
6
6
  ],