-
Notifications
You must be signed in to change notification settings - Fork 0
/
IJtAct.ts
154 lines (139 loc) · 5.26 KB
/
IJtAct.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Denis Kuzmin < entry.reg@gmail.com > GitHub/3F
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import { IJtConfig } from './IJtConfig';
import { IJt } from './IJt';
import { IJtHandler } from '../Handlers/IJtHandler';
import { IDictionary } from '../Types/IDictionary';
import { vrel } from '../Types/vrel';
export interface IJtAct
{
/**
* @returns Returns parent IJt container.
*/
jt(): IJt;
/**
* Chooses specific layer of data.
*
* @param index The index of layer starting from 1 (ie. 0 after `.use()`).
* @param offset Use as offset from this layer, eg.: `.as(-1, true)` will point to previous layer.
* @returns Returns itself IJtAct instance to continue chain.
*/
as(index: number, offset?: boolean): IJtAct;
/**
* Applies input values to the captured data in previous chain.
*
* @param values Key-value storage to apply.
* @returns Returns itself IJtAct instance to continue chain.
*/
as(values: IDictionary<vrel>): IJtAct;
/**
* Applies input values to the captured data in previous chain.
*
* @param values Key-value storage to apply.
* @param pair Access to `IJtConfig.pair` property.
* @returns Returns itself IJtAct instance to continue chain.
*/
as(values: IDictionary<vrel>, pair: string): IJtAct;
/**
* Applies input values to the captured data in previous chain.
*
* @param values Key-value storage to apply.
* @param cfg Configuration for applying data.
* @returns Returns itself IJtAct instance to continue chain.
*/
as(values: IDictionary<vrel>, cfg: IJtConfig): IJtAct;
/**
* Applies changing via custom handler.
* if/else; for; ...
*
* @param handler Custom handler that implements `IJtHandler`.
* @param data Specific data for this handler if needed.
* @returns Returns itself IJtAct instance to continue chain.
*/
sa(handler: IJtHandler, data?: any): IJtAct;
/**
* Applies changing via custom handler.
* if/else; for; ...
*
* Each handler may accept any number of configurations for its logic.
*
* For example, `JtIfHandler` accept 2:
* - 1. main config to configure general block eg. ~ {if(...)} ...
* - 2. config that affects for values inside if(...)
*
* therefore, you can pass your configurations as follow:
* ```
* .sa(jtif, { ... }, [ '{}', '%' ])
* .sa(jtif, { ... }, [ jtCfgInstance, { op: '@' } ])
* ```
*
* @param handler Custom handler that implements `IJtHandler`.
* @param data Specific data for this handler.
* @param cfg To configure this handler via list of possible configurations, ie. [ cfg1, cfg2, ... ]
* @returns Returns itself IJtAct instance to continue chain.
*/
sa(handler: IJtHandler, data: any, cfg: IJtConfig[] | string[]): IJtAct;
/**
* To clear chain after selected node.
*
* @returns Returns itself IJtAct instance to continue chain.
*/
clear(): IJtAct;
/**
* Access to actual layer.
* It may return anything because of custom handlers.
* While an `.val()` alternative will return only string.
*
* @returns Returns final data from selected chain.
*/
value(): any;
/**
* Wraps `.value()` to return empty string instead of possible falsy values.
*
* @returns Returns final data from selected chain.
*/
val(): string;
/**
* `.value()` alias with the continuing of the chain.
* @param cb Callback `(v: any) => void` on ejected data.
*/
eject(cb: (v: any) => void): IJtAct;
/**
* `.as(1)` alias that resets chain to the initial data.
*/
reset(): IJtAct;
/**
* `.as(latest)` alias that restores chain to the uppermost changes of the data.
*/
top(): IJtAct;
/**
* Binds values with custom raw data.
*
* @param raw Custom raw data.
* @param values Key-value storage to apply.
* @param config Optional config instance.
* @returns Returns processed data with injected values.
*/
bind(raw: string | undefined, values?: IDictionary<vrel>, config?: IJtConfig): string | undefined;
}