Skip to content

Commit e344d18

Browse files
committed
add (spec.ts)
1 parent 108a9fa commit e344d18

File tree

153 files changed

+5840
-6369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+5840
-6369
lines changed

Diff for: package-lock.json

+3,353-3,278
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+12-9
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121
"licenses": [
2222
"MIT"
2323
],
24+
"dependencies": {},
2425
"devDependencies": {
26+
"@types/jquery": "^3.3.22",
2527
"@types/sinon": "^7.0.5",
2628
"app-bundler": "0.0.63",
27-
"atma": "^0.11.14",
29+
"atma": "^0.11.18",
2830
"atma-io-middleware-condcomments": "^1.2.6",
2931
"atma-io-middleware-importer": "^1.1.37",
3032
"atma-io-middleware-uglify": "^1.1.21",
31-
"includejs": "^0.15.8",
33+
"atma-loader-ts": "^1.1.11",
3234
"jsdoc-to-markdown": "git+https://github.com/tenbits/jsdoc-to-markdown"
3335
},
3436
"scripts": {
@@ -38,7 +40,9 @@
3840
"build-dev": "app-bundler --inspect-brk",
3941
"release": "atma release",
4042
"server": "atma server",
41-
"examples": "atma server"
43+
"examples": "atma server",
44+
"tick": "func() { echo \"$1\"; }; func",
45+
"list": "ls"
4246
},
4347
"keywords": [],
4448
"atma": {
@@ -56,6 +60,11 @@
5660
"atma-loader-ts"
5761
],
5862
"settings": {
63+
"atma-utest": {
64+
"include": {
65+
"amd": true
66+
}
67+
},
5968
"io": {
6069
"extensions": {
6170
"js": [
@@ -153,12 +162,6 @@
153162
}
154163
}
155164
},
156-
"dependencies": {
157-
"@types/jquery": "^3.3.22",
158-
"module-alias": "^2.1.0",
159-
"typescript": "^3.2.2",
160-
"typescript-require": "^0.2.10"
161-
},
162165
"app-bundler": {
163166
"apps": {
164167
"browser-default": {

Diff for: projects/mask-binding/src/BindingProvider.ts

+96-63
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { class_create } from '@utils/class';
2-
import { DomObjectTransport } from './DomObjectTransport';
2+
import { DomObjectTransport, IDomWay, IObjectWay } from './DomObjectTransport';
33
import { signal_parse } from './utils/signal';
44
import { log_error, log_warn } from '@core/util/reporters';
55

@@ -18,23 +18,57 @@ import { Component } from '@compo/exports';
1818

1919
export const CustomProviders = {};
2020

21-
export const BindingProvider = class_create({
22-
validations: null,
23-
constructor: function BindingProvider(model, element, ctr, bindingType) {
21+
export class BindingProvider {
22+
validations = null
23+
ctx = null
24+
25+
value: string
26+
property: string
27+
28+
expression: string
29+
30+
domSetter: string
31+
domGetter: string
32+
objSetter: string
33+
objGetter: string
34+
mapToObj: string
35+
mapToDom: string
36+
changeEvent: string
37+
typeof: string
38+
39+
slots: any
40+
pipes: any
41+
42+
parent: any
43+
44+
45+
dismiss: number = 0
46+
bindingType: string
47+
log = false
48+
logExpression: string
49+
signal_domChanged: string
50+
signal_objectChanged: string
51+
52+
pipe_domChanged: { pipe: string, signal: string}
53+
pipe_objectChanged: { pipe: string, signal: string}
54+
locked = false
55+
56+
domWay: IDomWay = DomObjectTransport.domWay
57+
objectWay: IObjectWay = DomObjectTransport.objectWay
58+
59+
binder: Function
60+
61+
constructor (public model, public element: HTMLElement, public ctr, bindingType?: string) {
2462
if (bindingType == null) {
2563
bindingType = 'dual';
2664

27-
var name = ctr.compoName;
65+
let name = ctr.compoName;
2866
if (name === ':bind' || name === 'bind') {
2967
bindingType = 'single';
3068
}
3169
}
32-
var attr = ctr.attr;
70+
let attr = ctr.attr;
3371

34-
this.ctr = ctr;
35-
this.ctx = null;
36-
this.model = model;
37-
this.element = element;
3872
this.value = attr.value;
3973
this.property = attr.property;
4074
this.domSetter = attr['dom-setter'] || attr.setter;
@@ -48,14 +82,9 @@ export const BindingProvider = class_create({
4882
/* Convert to an instance, e.g. Number, on domchange event */
4983
this['typeof'] = attr['typeof'] || null;
5084

51-
this.dismiss = 0;
5285
this.bindingType = bindingType;
53-
this.log = false;
54-
this.signal_domChanged = null;
55-
this.signal_objectChanged = null;
56-
this.locked = false;
57-
58-
var isCompoBinder = ctr.node.parent.tagName === ctr.parent.compoName;
86+
87+
let isCompoBinder = ctr.node.parent.tagName === ctr.parent.compoName;
5988
if (
6089
isCompoBinder &&
6190
(element.nodeType !== 1 || element.tagName !== 'INPUT')
@@ -88,14 +117,14 @@ export const BindingProvider = class_create({
88117
this.domWay = x.domWay;
89118
break;
90119
}
91-
this.changeEvent = attr['change-event'] || 'input';
120+
this.changeEvent = attr['change-event'] || 'change,input';
92121
this.property = 'element.value';
93122
break;
94123
case 'TEXTAREA':
95124
this.property = 'element.value';
96125
break;
97126
case 'SELECT':
98-
this.domWay = element.multiple
127+
this.domWay = (element as HTMLSelectElement).multiple
99128
? DomObjectTransport.SELECT_MULT
100129
: DomObjectTransport.SELECT;
101130
break;
@@ -191,11 +220,11 @@ export const BindingProvider = class_create({
191220
}
192221

193222
this.expression = this.value;
194-
},
195-
dispose: function() {
223+
}
224+
dispose () {
196225
expression_unbind(this.expression, this.model, this.ctr, this.binder);
197-
},
198-
objectChanged: function(x) {
226+
}
227+
objectChanged (val?) {
199228
if (this.dismiss-- > 0) {
200229
return;
201230
}
@@ -205,61 +234,61 @@ export const BindingProvider = class_create({
205234
}
206235
this.locked = true;
207236

208-
if (x == null || this.objGetter != null) {
209-
x = this.objectWay.get(this, this.expression);
237+
if (val == null || this.objGetter != null) {
238+
val = this.objectWay.get(this, this.expression);
210239
}
211240
if (this.mapToDom != null) {
212-
x = expression_callFn(this.mapToDom, this.model, null, this.ctr, [
213-
x
241+
val = expression_callFn(this.mapToDom, this.model, null, this.ctr, [
242+
val
214243
]);
215244
}
216245

217-
this.domWay.set(this, x);
246+
this.domWay.set(this, val);
218247

219248
if (this.log) {
220-
console.log('[BindingProvider] objectChanged -', x);
249+
console.log('[BindingProvider] objectChanged -', val);
221250
}
222251
if (this.signal_objectChanged) {
223252
Component.signal.emitOut(
224253
this.ctr,
225254
this.signal_objectChanged,
226255
this.ctr,
227-
[x]
256+
[val]
228257
);
229258
}
230-
if (this.pipe_objectChanged) {
259+
if (this.pipe_objectChanged != null) {
231260
var pipe = this.pipe_objectChanged;
232261
Component.pipe(pipe.pipe).emit(pipe.signal);
233-
}
234-
262+
}
235263
this.locked = false;
236-
},
237-
domChanged: function(event, val_) {
264+
}
265+
266+
domChanged (event?, val?) {
238267
if (this.locked === true) {
239268
log_warn('Concurance change detected', this);
240269
return;
241270
}
242271
this.locked = true;
243272

244-
var value = val_;
245-
if (value == null) value = this.domWay.get(this);
246-
247-
var typeof_ = this['typeof'];
273+
if (val == null) {
274+
val = this.domWay.get(this);
275+
}
276+
let typeof_ = this['typeof'];
248277
if (typeof_ != null) {
249-
var Converter = window[typeof_];
250-
value = Converter(value);
278+
let Converter = window[typeof_];
279+
val = Converter(val);
251280
}
252281
if (this.mapToObj != null) {
253-
value = expression_callFn(
282+
val = expression_callFn(
254283
this.mapToObj,
255284
this.model,
256285
null,
257286
this.ctr,
258-
[value]
287+
[val]
259288
);
260289
}
261290

262-
var error = this.validate(value);
291+
var error = this.validate(val);
263292
if (error == null) {
264293
this.dismiss = 1;
265294

@@ -272,19 +301,19 @@ export const BindingProvider = class_create({
272301
if (tuple != null) {
273302
var obj = tuple[0],
274303
prop = tuple[1];
275-
this.objectWay.set(obj, prop, value, this);
304+
this.objectWay.set(obj, prop, val, this);
276305
}
277306

278307
this.dismiss = 0;
279308
if (this.log) {
280-
console.log('[BindingProvider] domChanged -', value);
309+
console.log('[BindingProvider] domChanged -', val);
281310
}
282311
if (this.signal_domChanged != null) {
283312
Component.signal.emitOut(
284313
this.ctr,
285314
this.signal_domChanged,
286315
this.ctr,
287-
[value]
316+
[val]
288317
);
289318
}
290319
if (this.pipe_domChanged != null) {
@@ -293,8 +322,8 @@ export const BindingProvider = class_create({
293322
}
294323
}
295324
this.locked = false;
296-
},
297-
addValidation: function(mix) {
325+
}
326+
addValidation (mix) {
298327
if (this.validations == null) {
299328
this.validations = [];
300329
}
@@ -303,8 +332,8 @@ export const BindingProvider = class_create({
303332
return;
304333
}
305334
this.validations.push(mix);
306-
},
307-
validate: function(val) {
335+
}
336+
validate (val) {
308337
var fns = this.validations,
309338
ctr = this.ctr,
310339
el = this.element;
@@ -320,13 +349,9 @@ export const BindingProvider = class_create({
320349
el,
321350
this.objectChanged.bind(this)
322351
);
323-
},
324-
objectWay: DomObjectTransport.objectWay,
325-
domWay: DomObjectTransport.domWay
326-
});
352+
}
327353

328-
export const BindingProviderStatics = {
329-
create: function(model, el, ctr, bindingType?) {
354+
static create (model, el, ctr, bindingType?) {
330355
/* Initialize custom provider */
331356
var type = ctr.attr.bindingProvider,
332357
CustomProvider = type == null ? null : CustomProviders[type],
@@ -342,14 +367,15 @@ export const BindingProviderStatics = {
342367
obj_extend(provider, CustomProvider);
343368
}
344369
return provider;
345-
},
370+
}
346371

347-
bind: function(provider) {
372+
static bind (provider) {
348373
return apply_bind(provider);
349374
}
350-
};
375+
}
351376

352-
function apply_bind(provider) {
377+
378+
function apply_bind(provider: BindingProvider) {
353379
var expr = provider.expression,
354380
model = provider.model,
355381
onObjChanged = (provider.objectChanged = provider.objectChanged.bind(
@@ -372,9 +398,16 @@ function apply_bind(provider) {
372398
if (!attr['dom-slot'] && !attr['change-pipe-event']) {
373399
var element = provider.element,
374400
eventType = provider.changeEvent,
375-
onDomChange = provider.domChanged.bind(provider);
401+
onDomChange = provider.domChanged.bind(provider),
402+
doListen = Component.Dom.addEventListener;
376403

377-
Component.Dom.addEventListener(element, eventType, onDomChange);
404+
if (eventType.indexOf(',') !== -1) {
405+
let arr = eventType.split(',');
406+
for (let i = 0; i < arr.length; i++) {
407+
doListen(element, arr[i].trim(), onDomChange);
408+
}
409+
}
410+
doListen(element, eventType, onDomChange);
378411
}
379412

380413
if (provider.objectWay.get(provider, provider.expression) == null) {

Diff for: projects/mask-binding/src/DomObjectTransport.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ import { date_ensure } from './utils/date';
55
import { log_warn, log_error } from '@core/util/reporters';
66
import { coll_map, coll_each } from '@utils/coll';
77
import { is_ArrayLike } from '@utils/is';
8+
import { BindingProvider } from './BindingProvider';
89

10+
export interface IObjectWay {
11+
get (provider: BindingProvider, expression: string): any
12+
set (obj, property: string, value, provider: BindingProvider)
13+
};
14+
export interface IDomWay {
15+
get (provider: BindingProvider): any
16+
set (provider: BindingProvider, value: any)
17+
}
918

10-
var objectWay = {
19+
var objectWay = <IObjectWay> {
1120
get: function(provider, expression) {
1221
var getter = provider.objGetter;
1322
if (getter == null) {
@@ -46,7 +55,7 @@ var objectWay = {
4655
);
4756
}
4857
};
49-
var domWay = {
58+
var domWay = <IDomWay> {
5059
get: function(provider) {
5160
var getter = provider.domGetter;
5261
if (getter == null) {

0 commit comments

Comments
 (0)