targetj 1.0.71 → 1.0.73
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 +68 -19
- package/package.json +1 -1
- package/src/LocationManager.js +1 -1
- package/src/TModel.js +3 -3
- package/src/TModelManager.js +1 -1
- package/src/TargetManager.js +2 -2
package/README.md
CHANGED
|
@@ -4,47 +4,58 @@ Welcome to TargetJ, a powerful JavaScript UI framework designed to simplify deve
|
|
|
4
4
|
|
|
5
5
|
TargetJ distinguishes itself by introducing a novel concept known as 'targets', which forms its core. Targets are used as the main building blocks of components instead of direct variables and methods. Each component in TargetJ is a set of targets. Targets are employed across all aspects of the program. They are used in animation, controlling program flow, loading data from external APIs, handling user events, and more.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Targets enhance both variables and methods by giving them lifecycles and the autonomy to run independently, rather than always being controlled externally. They can execute under specific conditions, manage the number and timing of executions, and provide callbacks to oversee their life cycles.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## What are targets?
|
|
10
|
+
|
|
11
|
+
Targets provide a unified, autonomous approach for managing passive variables and methods, mimicking the behavior of live cells in living beings. They largely manage themselves autonomously, with various callbacks available to adjust for changes.
|
|
12
|
+
|
|
13
|
+
For variables, targets enhance functionality by giving them the ability to iterate in steps until they reach the specified value, rather rather than being immediately assigned their values. They can introduce pauses between iterations and offer callbacks to monitor progress, track the progress of other variables, and manage their life cycles accordingly.
|
|
14
|
+
|
|
15
|
+
Similarly, targets enhance methods by allowing them to manage their own life cycles. They execute under specific conditions, control the number of executions, and offer the same capabilities as those provided to variables.
|
|
16
|
+
|
|
17
|
+
## What does a target consist of?
|
|
10
18
|
|
|
11
19
|
Each target consists of the following:
|
|
12
|
-
1. Target Value and Actual Value. The target
|
|
20
|
+
1. Target Value and Actual Value. The target value represents a variable or the outcome of a method. The actual value reflects the transitional value between the previous target value and the current target value. When the target value differs from the actual value, TargetJ iteratively updates the actual value until it matches the target value. This process is managed by two additional variables: Step, which dictates the number of iterations, and Interval, which specifies the duration (in milliseconds) the system waits before executing the next iteration.
|
|
13
21
|
|
|
14
|
-
2. State: Targets have three states that control their lifecycle:
|
|
22
|
+
2. State: Targets have three states that control their lifecycle: Active, Updating, and Complete. Active: Indicates that the target value needs to be initialized from the variable or that the method needs to be executed to calculate its output. Updating: Indicates that the actual value is being adjusted to reach the target value. Complete: Indicates that the target execution is finished, and the actual value has matched the target value.
|
|
15
23
|
|
|
16
|
-
3. Target Methods: All methods are optional. They are used to control the lifecycle of targets or serve as callbacks to reflect changes. The controlling methods are: enabledOn, loop, steps, cycles. The callbacks are: onValueChange, onStepsEnd, onImperativeStep, onImperativeEnd.
|
|
24
|
+
3. Target Methods: All methods are optional. They are used to control the lifecycle of targets or serve as callbacks to reflect changes. The controlling methods are: enabledOn, loop, steps, cycles. The callbacks are: onValueChange, onStepsEnd, onImperativeStep, onImperativeEnd. More details in the method section.
|
|
17
25
|
|
|
18
26
|
## Brief overview of how it operates
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
All targets are in the active state by default. They can include an enabledOn function that delays their execution until the specified conditions are met. Targets can also be set to inactive and activated externally when needed. The target task monitors all active targets, and if a target is enabled, it will be executed. The target value is generated either from the result of a method or from a static value defined in the target. For simple targets without steps, cycles, or loops, the actual value is set immediately based on the target value. Once executed, the target’s state becomes complete, and it will not be executed again.
|
|
29
|
+
|
|
30
|
+
If the target has loop or cycle methods defined, its value method will be re-executed after a pause specified by the interval. The number of executions will be determined by the cycles or will continue as long as the loop condition returns true. If the target has steps defined, its state changes to updating, and the actual value is updated iteratively until it reaches the target value, according to the number of steps and pauses specified by steps and intervals.
|
|
21
31
|
|
|
22
|
-
|
|
32
|
+
A target can reactivate itself under various conditions, such as when all steps are completed, all imperative targets initiated by that target are completed, or the targets of the component’s children are completed. It can also be reactivated externally, either directly or through an event.
|
|
23
33
|
|
|
24
|
-
## Target
|
|
34
|
+
## Target methods
|
|
25
35
|
|
|
26
|
-
|
|
36
|
+
1. **Value**
|
|
37
|
+
If defined, value is the primary target method that will be executed. The target value will be calculated based on the result of value().
|
|
27
38
|
|
|
28
|
-
|
|
39
|
+
2. **onEnabled**
|
|
29
40
|
Determines whether the target is eligible for execution. If enabledOn() returns false, the target remains active until it is enabled and gets executed.
|
|
30
41
|
|
|
31
|
-
|
|
42
|
+
3. **loop**
|
|
32
43
|
Controls the repetition of target execution. If loop() returns true, the target will continue to execute indefinitely. It can also be defined as a boolean instead of a method.
|
|
33
44
|
|
|
34
|
-
|
|
45
|
+
4. **cycles**
|
|
35
46
|
Its purpose is similar to loop, but the number of repetitions is specified explicitly as a number.
|
|
36
47
|
|
|
37
|
-
|
|
48
|
+
5. **interval**
|
|
38
49
|
It specifies the pause between each target execution or each actual value update when steps are defined.
|
|
39
50
|
|
|
40
|
-
|
|
51
|
+
6. **steps**
|
|
41
52
|
By default, the actual value is updated immediately after the target value. The steps option allows the actual value to be updated in iterations specified by the number of steps.
|
|
42
53
|
|
|
43
|
-
|
|
54
|
+
7. **easing**
|
|
44
55
|
An easing function that operates when steps are defined. It controls how the actual value is updated in relation to the steps.
|
|
45
56
|
|
|
46
57
|
8. **onValueChange**
|
|
47
|
-
This callbak is triggered whenever there is a change returned by the target value().
|
|
58
|
+
This callbak is triggered whenever there is a change returned by the target method, which is called value().
|
|
48
59
|
|
|
49
60
|
9. **onStepsEnd**
|
|
50
61
|
This method is invoked only after the final step of updating the actual value is completed, assuming the target has a defined steps value.
|
|
@@ -55,13 +66,51 @@ onImperativeStep() This callback tracks the progress of imperative targets defin
|
|
|
55
66
|
11. **onImperativeEnd**
|
|
56
67
|
It is similar to onImperativeStep, but it is called when the imperative target is completed.
|
|
57
68
|
|
|
69
|
+
### Simple example
|
|
70
|
+
|
|
71
|
+
In the example below, we incrementally increase the value of width, height, and opacity in 30 steps, with a 50-milliseconds pause between each step.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
import { App, TModel } from 'targetj';
|
|
75
|
+
|
|
76
|
+
App(new TModel({
|
|
77
|
+
background: '#fff',
|
|
78
|
+
width: {
|
|
79
|
+
value: 250,
|
|
80
|
+
steps: 30,
|
|
81
|
+
stepInterval: 50
|
|
82
|
+
},
|
|
83
|
+
height: {
|
|
84
|
+
value: 250,
|
|
85
|
+
steps: 30,
|
|
86
|
+
stepInterval: 50
|
|
87
|
+
},
|
|
88
|
+
opacity: {
|
|
89
|
+
value: 0.15,
|
|
90
|
+
steps: 30,
|
|
91
|
+
stepInterval: 50
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
It can also be written in a more compact form using arrays:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
import { App, TModel } from 'targetj';
|
|
100
|
+
|
|
101
|
+
App(new TModel({
|
|
102
|
+
background: '#fff',
|
|
103
|
+
width: [ 250, 30, 50],
|
|
104
|
+
height: [ 250, 30, 50],
|
|
105
|
+
opacity: [ 0.15, 30, 50]
|
|
106
|
+
}));
|
|
107
|
+
```
|
|
108
|
+
|
|
58
109
|
## Declarative and imperative targets
|
|
59
110
|
|
|
60
111
|
Targets in TargetJ can be defined in two ways: declaratively or imperatively.
|
|
61
112
|
|
|
62
|
-
The declarative approach offers a structured
|
|
63
|
-
|
|
64
|
-
To address this, TargetJ provides a way to call imperative targets using the setTarget function. This allows you to set multiple targets from one declarative target. Additionally, it offers onImperativeStep and onImperativeEnd callbacks, which enable declarative targets to track every step of each imperative target or just their completion.
|
|
113
|
+
The declarative approach offers a structured method for defining targets, as seen in the previous example. However, orchestrating multiple targets with varying speeds and timings can be challenging. For instance, tracking the completion of multiple targets to trigger a new set of targets is not easily done using only declarative targets. To address this, TargetJ provides the setTarget function, allowing you to define multiple targets from within a single declarative target. Additionally, the onImperativeStep and onImperativeEnd callbacks, defined in the declarative target, enable you to track each step of the imperative targets or just their completion.
|
|
65
114
|
|
|
66
115
|
By combining both declarative and imperative targets, you gain a powerful toolset for designing complex interactions.
|
|
67
116
|
|
package/package.json
CHANGED
package/src/LocationManager.js
CHANGED
|
@@ -202,7 +202,7 @@ LocationManager.prototype.activateTargetsOnEvents = function(tmodel) {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
if (
|
|
205
|
+
if (getEvents().currentKey && tmodel.targets['onKeyEvent']) {
|
|
206
206
|
activateTargets = activateTargets.concat(tmodel.targets['onKeyEvent']);
|
|
207
207
|
}
|
|
208
208
|
|
package/src/TModel.js
CHANGED
|
@@ -203,7 +203,7 @@ TModel.prototype.getChildren = function() {
|
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
205
|
if (this.targetValues['allChildren']) {
|
|
206
|
-
this.setActualValueLastUpdate('allChildren')
|
|
206
|
+
this.setActualValueLastUpdate('allChildren');
|
|
207
207
|
} else {
|
|
208
208
|
this.setTarget('allChildren', this.actualValues.allChildren);
|
|
209
209
|
}
|
|
@@ -726,7 +726,7 @@ TModel.prototype.getTargetEventFunctions = function(key) {
|
|
|
726
726
|
TModel.prototype.setTarget = function(key, value, steps, interval, easing, originalTargetName) {
|
|
727
727
|
|
|
728
728
|
originalTargetName = originalTargetName || this.key;
|
|
729
|
-
TargetExecutor.executeImperativeTarget(this, key, value, steps, interval, easing, originalTargetName)
|
|
729
|
+
TargetExecutor.executeImperativeTarget(this, key, value, steps, interval, easing, originalTargetName);
|
|
730
730
|
|
|
731
731
|
return this;
|
|
732
732
|
};
|
|
@@ -878,7 +878,7 @@ TModel.prototype.deleteTargetValue = function(key) {
|
|
|
878
878
|
this.removeFromUpdatingTargets(key);
|
|
879
879
|
|
|
880
880
|
tapp.manager.scheduleRun(10, 'deleteTargetValue-' + this.oid + "-" + key);
|
|
881
|
-
}
|
|
881
|
+
};
|
|
882
882
|
|
|
883
883
|
TModel.prototype.resetImperative = function(key) {
|
|
884
884
|
var targetValue = this.targetValues[key];
|
package/src/TModelManager.js
CHANGED
package/src/TargetManager.js
CHANGED
|
@@ -38,14 +38,14 @@ TargetManager.prototype.applyTargetValue = function(tmodel, key) {
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
if (tmodel.getTargetStep(key) === tmodel.getTargetSteps(key)) {
|
|
41
|
+
if (tmodel.isExecuted(key) && tmodel.getTargetStep(key) === tmodel.getTargetSteps(key)) {
|
|
42
42
|
if (TargetUtil.scheduleExecution(tmodel, key) > 0) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
tmodel.resetScheduleTimeStamp(key);
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
if (tmodel.isExecuted(key) && tmodel.getTargetCycle(key) < tmodel.getTargetCycles(key)) {
|
|
50
50
|
tmodel.setTargetCycle(key, tmodel.getTargetCycle(key) + 1);
|
|
51
51
|
tmodel.resetTargetStep(key);
|