wallace 0.0.1 → 0.0.2
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 +3 -0
- package/dist/wallace.js +45 -20
- package/package.json +6 -4
- package/src/component.js +36 -10
- package/src/lookup.js +2 -0
- package/src/wrapper.js +7 -10
package/README.md
ADDED
package/dist/wallace.js
CHANGED
|
@@ -53,13 +53,7 @@ Wrapper.prototype = {
|
|
|
53
53
|
return this
|
|
54
54
|
},
|
|
55
55
|
att: function(name, value) {
|
|
56
|
-
this.e
|
|
57
|
-
return this
|
|
58
|
-
},
|
|
59
|
-
atts: function(atts) {
|
|
60
|
-
for (let name in atts) {
|
|
61
|
-
this.att(name, atts[name]);
|
|
62
|
-
}
|
|
56
|
+
this.e[name] = value;
|
|
63
57
|
return this
|
|
64
58
|
},
|
|
65
59
|
pool: function(pool) {
|
|
@@ -143,7 +137,7 @@ Wrapper.prototype = {
|
|
|
143
137
|
src: function(value) {
|
|
144
138
|
return this.att('src', value)
|
|
145
139
|
},
|
|
146
|
-
style: function(
|
|
140
|
+
style: function(value, name) {
|
|
147
141
|
this.e.style[name] = value;
|
|
148
142
|
return this
|
|
149
143
|
},
|
|
@@ -155,8 +149,11 @@ Wrapper.prototype = {
|
|
|
155
149
|
this.e.textContent = value;
|
|
156
150
|
return this
|
|
157
151
|
},
|
|
158
|
-
|
|
159
|
-
this
|
|
152
|
+
hidden: function(value) {
|
|
153
|
+
// TODO: fix this - it works in browser, is it just tests?
|
|
154
|
+
this.e.classList.toggle('hidden', value);
|
|
155
|
+
// console.log('hidden', value)
|
|
156
|
+
// this.e.hidden = !value
|
|
160
157
|
return this
|
|
161
158
|
},
|
|
162
159
|
value: function(value) {
|
|
@@ -442,7 +439,9 @@ Lookup.prototype = {
|
|
|
442
439
|
// Verbose but efficient way as it avoids lookups?
|
|
443
440
|
// Or is this harmful to performance because we're just reading values more than calling functions?
|
|
444
441
|
let o = component.__ov[key];
|
|
442
|
+
// TODO: is this checking for watchOnce?
|
|
445
443
|
o = und(o) ? '' : o;
|
|
444
|
+
// console.log(key)
|
|
446
445
|
const n = this.callbacks[key](component, component.props);
|
|
447
446
|
const c = n !== o;
|
|
448
447
|
component.__ov[key] = n;
|
|
@@ -477,6 +476,26 @@ function Component(parent) {
|
|
|
477
476
|
}
|
|
478
477
|
|
|
479
478
|
|
|
479
|
+
|
|
480
|
+
Component.extend = function(opts) {
|
|
481
|
+
var base = opts._base || Component;
|
|
482
|
+
// TODO: do we care about allowing this?
|
|
483
|
+
// var NewComponent = opts.hasOwnProperty('constructor') ? opts.constructor : function(parent) {
|
|
484
|
+
|
|
485
|
+
// TODO: This ends up being the name of the function, used in logging etc.
|
|
486
|
+
// Maybe change with Object.defineProperty() or use object hack {name: func....}
|
|
487
|
+
var CustomComponent = function(parent) {
|
|
488
|
+
base.call(this, parent);
|
|
489
|
+
};
|
|
490
|
+
delete opts._base;
|
|
491
|
+
CustomComponent.prototype = Object.create(base && base.prototype, {
|
|
492
|
+
constructor: { value: CustomComponent, writable: true, configurable: true }
|
|
493
|
+
});
|
|
494
|
+
Object.assign(CustomComponent.prototype, opts);
|
|
495
|
+
return CustomComponent
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
|
|
480
499
|
var proto = Component.prototype;
|
|
481
500
|
|
|
482
501
|
proto.onUpdate = noop;
|
|
@@ -507,14 +526,17 @@ proto.init = function() {
|
|
|
507
526
|
*/
|
|
508
527
|
proto.bubble = function(name) {
|
|
509
528
|
let target = this.parent;
|
|
510
|
-
while (
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
529
|
+
while (target) {
|
|
530
|
+
// console.log(target.name)
|
|
531
|
+
let func = target[name];
|
|
532
|
+
if (func) {
|
|
533
|
+
// We don't really care about performance here, so accessing arguments is fine.
|
|
534
|
+
// TODO: maybe we do care, so pass as array? Or use proxy?
|
|
535
|
+
return func.apply(target, Array.prototype.slice.call(arguments, 1))
|
|
514
536
|
}
|
|
515
537
|
target = target.parent;
|
|
516
538
|
}
|
|
517
|
-
throw 'Bubble popped.'
|
|
539
|
+
throw new Error('Bubble popped.')
|
|
518
540
|
};
|
|
519
541
|
/**
|
|
520
542
|
* Move the component to new parent. Necessary if sharing a pool.
|
|
@@ -588,7 +610,7 @@ proto.updateSelf = function() {
|
|
|
588
610
|
shouldBeVisible = true;
|
|
589
611
|
if (shieldQuery) {
|
|
590
612
|
// Get the newValue for shieldQuery using lookup
|
|
591
|
-
shieldQueryResult = this.lookup(shieldQuery).n;
|
|
613
|
+
shieldQueryResult = !!this.lookup(shieldQuery).n;
|
|
592
614
|
|
|
593
615
|
// Determine if shouldBeVisible based on reverseShield
|
|
594
616
|
// i.e. whether "shieldQuery===true" means show or hide.
|
|
@@ -598,7 +620,7 @@ proto.updateSelf = function() {
|
|
|
598
620
|
shieldCount = shouldBeVisible ? 0 : watch.sc;
|
|
599
621
|
|
|
600
622
|
// Set the element visibility
|
|
601
|
-
wrapper.
|
|
623
|
+
wrapper.hidden(!shouldBeVisible);
|
|
602
624
|
i += shieldCount;
|
|
603
625
|
}
|
|
604
626
|
if (shouldBeVisible) {
|
|
@@ -659,9 +681,11 @@ const applyWatchCallbacks = (component, wrapper, callbacks) => {
|
|
|
659
681
|
|
|
660
682
|
for (let key in callbacks) {
|
|
661
683
|
let callback = callbacks[key];
|
|
684
|
+
// TODO: change this to use constant.
|
|
662
685
|
if (key === '*') {
|
|
663
686
|
callback.call(component, wrapper, component.props, component);
|
|
664
687
|
} else {
|
|
688
|
+
// TODO: will this transpile to something different?
|
|
665
689
|
// means: {new, old, changed}
|
|
666
690
|
const {n, o, c} = component.lookup(key);
|
|
667
691
|
if (c) {
|
|
@@ -692,7 +716,8 @@ proto.__ni = function(path, cls) {
|
|
|
692
716
|
* @param {object} [prototypeExtras] - an object with extra things to be added to the prototype
|
|
693
717
|
* @param {function} [prototypeExtras] - the function to be used as constructor
|
|
694
718
|
*/
|
|
695
|
-
|
|
719
|
+
proto.__ex = function(baseClass, prototypeExtras, constructorFunction) {
|
|
720
|
+
// const base = baseClass || Component
|
|
696
721
|
var subClass = constructorFunction || function(parent) {
|
|
697
722
|
baseClass.call(this, parent);
|
|
698
723
|
};
|
|
@@ -793,8 +818,8 @@ proto.__sv = function() {
|
|
|
793
818
|
/**
|
|
794
819
|
* Toggles visibility, like wrapper.
|
|
795
820
|
*/
|
|
796
|
-
proto.
|
|
797
|
-
this.e.
|
|
821
|
+
proto.hide = function(hidden) {
|
|
822
|
+
this.e.hidden = hidden;
|
|
798
823
|
};
|
|
799
824
|
|
|
800
825
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wallace",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "The framework that brings you freedom.",
|
|
5
5
|
"babel": {
|
|
6
6
|
"presets": [
|
|
@@ -21,15 +21,17 @@
|
|
|
21
21
|
"prepublish": "npm run build",
|
|
22
22
|
"build": "NODE_ENV=production rollup -c",
|
|
23
23
|
"test": "jest --clearCache && jest",
|
|
24
|
-
"clear
|
|
24
|
+
"jest-clear": "jest --clearCache"
|
|
25
25
|
},
|
|
26
26
|
"author": "Andrew Buchan",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
30
|
-
"babel
|
|
30
|
+
"@babel/plugin-syntax-jsx": "^7.22.5",
|
|
31
|
+
"babel-plugin-wallace": "^0.0.2",
|
|
32
|
+
"jest-summary-reporter": "^0.0.2"
|
|
31
33
|
},
|
|
32
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "922a989fa10d19dbcd2aaffe725d075a85214a73",
|
|
33
35
|
"devDependencies": {
|
|
34
36
|
"rollup": "^3.27.0"
|
|
35
37
|
}
|
package/src/component.js
CHANGED
|
@@ -25,6 +25,26 @@ export function Component(parent) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
|
|
29
|
+
Component.extend = function(opts) {
|
|
30
|
+
var base = opts._base || Component
|
|
31
|
+
// TODO: do we care about allowing this?
|
|
32
|
+
// var NewComponent = opts.hasOwnProperty('constructor') ? opts.constructor : function(parent) {
|
|
33
|
+
|
|
34
|
+
// TODO: This ends up being the name of the function, used in logging etc.
|
|
35
|
+
// Maybe change with Object.defineProperty() or use object hack {name: func....}
|
|
36
|
+
var CustomComponent = function(parent) {
|
|
37
|
+
base.call(this, parent)
|
|
38
|
+
}
|
|
39
|
+
delete opts._base
|
|
40
|
+
CustomComponent.prototype = Object.create(base && base.prototype, {
|
|
41
|
+
constructor: { value: CustomComponent, writable: true, configurable: true }
|
|
42
|
+
})
|
|
43
|
+
Object.assign(CustomComponent.prototype, opts)
|
|
44
|
+
return CustomComponent
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
28
48
|
var proto = Component.prototype
|
|
29
49
|
|
|
30
50
|
proto.onUpdate = noop
|
|
@@ -55,14 +75,17 @@ proto.init = function() {
|
|
|
55
75
|
*/
|
|
56
76
|
proto.bubble = function(name) {
|
|
57
77
|
let target = this.parent
|
|
58
|
-
while (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
78
|
+
while (target) {
|
|
79
|
+
// console.log(target.name)
|
|
80
|
+
let func = target[name]
|
|
81
|
+
if (func) {
|
|
82
|
+
// We don't really care about performance here, so accessing arguments is fine.
|
|
83
|
+
// TODO: maybe we do care, so pass as array? Or use proxy?
|
|
84
|
+
return func.apply(target, Array.prototype.slice.call(arguments, 1))
|
|
62
85
|
}
|
|
63
86
|
target = target.parent
|
|
64
87
|
}
|
|
65
|
-
throw 'Bubble popped.'
|
|
88
|
+
throw new Error('Bubble popped.')
|
|
66
89
|
}
|
|
67
90
|
/**
|
|
68
91
|
* Move the component to new parent. Necessary if sharing a pool.
|
|
@@ -136,7 +159,7 @@ proto.updateSelf = function() {
|
|
|
136
159
|
shouldBeVisible = true
|
|
137
160
|
if (shieldQuery) {
|
|
138
161
|
// Get the newValue for shieldQuery using lookup
|
|
139
|
-
shieldQueryResult = this.lookup(shieldQuery).n
|
|
162
|
+
shieldQueryResult = !!this.lookup(shieldQuery).n
|
|
140
163
|
|
|
141
164
|
// Determine if shouldBeVisible based on reverseShield
|
|
142
165
|
// i.e. whether "shieldQuery===true" means show or hide.
|
|
@@ -146,7 +169,7 @@ proto.updateSelf = function() {
|
|
|
146
169
|
shieldCount = shouldBeVisible ? 0 : watch.sc
|
|
147
170
|
|
|
148
171
|
// Set the element visibility
|
|
149
|
-
wrapper.
|
|
172
|
+
wrapper.hidden(!shouldBeVisible)
|
|
150
173
|
i += shieldCount
|
|
151
174
|
}
|
|
152
175
|
if (shouldBeVisible) {
|
|
@@ -207,9 +230,11 @@ const applyWatchCallbacks = (component, wrapper, callbacks) => {
|
|
|
207
230
|
|
|
208
231
|
for (let key in callbacks) {
|
|
209
232
|
let callback = callbacks[key]
|
|
233
|
+
// TODO: change this to use constant.
|
|
210
234
|
if (key === '*') {
|
|
211
235
|
callback.call(component, wrapper, component.props, component)
|
|
212
236
|
} else {
|
|
237
|
+
// TODO: will this transpile to something different?
|
|
213
238
|
// means: {new, old, changed}
|
|
214
239
|
const {n, o, c} = component.lookup(key)
|
|
215
240
|
if (c) {
|
|
@@ -240,7 +265,8 @@ proto.__ni = function(path, cls) {
|
|
|
240
265
|
* @param {object} [prototypeExtras] - an object with extra things to be added to the prototype
|
|
241
266
|
* @param {function} [prototypeExtras] - the function to be used as constructor
|
|
242
267
|
*/
|
|
243
|
-
|
|
268
|
+
proto.__ex = function(baseClass, prototypeExtras, constructorFunction) {
|
|
269
|
+
// const base = baseClass || Component
|
|
244
270
|
var subClass = constructorFunction || function(parent) {
|
|
245
271
|
baseClass.call(this, parent)
|
|
246
272
|
}
|
|
@@ -341,6 +367,6 @@ proto.__sv = function() {
|
|
|
341
367
|
/**
|
|
342
368
|
* Toggles visibility, like wrapper.
|
|
343
369
|
*/
|
|
344
|
-
proto.
|
|
345
|
-
this.e.
|
|
370
|
+
proto.hide = function(hidden) {
|
|
371
|
+
this.e.hidden = hidden
|
|
346
372
|
}
|
package/src/lookup.js
CHANGED
|
@@ -19,7 +19,9 @@ Lookup.prototype = {
|
|
|
19
19
|
// Verbose but efficient way as it avoids lookups?
|
|
20
20
|
// Or is this harmful to performance because we're just reading values more than calling functions?
|
|
21
21
|
let o = component.__ov[key]
|
|
22
|
+
// TODO: is this checking for watchOnce?
|
|
22
23
|
o = und(o) ? '' : o
|
|
24
|
+
// console.log(key)
|
|
23
25
|
const n = this.callbacks[key](component, component.props)
|
|
24
26
|
const c = n !== o
|
|
25
27
|
component.__ov[key] = n
|
package/src/wrapper.js
CHANGED
|
@@ -39,13 +39,7 @@ Wrapper.prototype = {
|
|
|
39
39
|
return this
|
|
40
40
|
},
|
|
41
41
|
att: function(name, value) {
|
|
42
|
-
this.e
|
|
43
|
-
return this
|
|
44
|
-
},
|
|
45
|
-
atts: function(atts) {
|
|
46
|
-
for (let name in atts) {
|
|
47
|
-
this.att(name, atts[name])
|
|
48
|
-
}
|
|
42
|
+
this.e[name] = value
|
|
49
43
|
return this
|
|
50
44
|
},
|
|
51
45
|
pool: function(pool) {
|
|
@@ -129,7 +123,7 @@ Wrapper.prototype = {
|
|
|
129
123
|
src: function(value) {
|
|
130
124
|
return this.att('src', value)
|
|
131
125
|
},
|
|
132
|
-
style: function(
|
|
126
|
+
style: function(value, name) {
|
|
133
127
|
this.e.style[name] = value
|
|
134
128
|
return this
|
|
135
129
|
},
|
|
@@ -141,8 +135,11 @@ Wrapper.prototype = {
|
|
|
141
135
|
this.e.textContent = value
|
|
142
136
|
return this
|
|
143
137
|
},
|
|
144
|
-
|
|
145
|
-
this
|
|
138
|
+
hidden: function(value) {
|
|
139
|
+
// TODO: fix this - it works in browser, is it just tests?
|
|
140
|
+
this.e.classList.toggle('hidden', value)
|
|
141
|
+
// console.log('hidden', value)
|
|
142
|
+
// this.e.hidden = !value
|
|
146
143
|
return this
|
|
147
144
|
},
|
|
148
145
|
value: function(value) {
|