leaner 0.1.1 → 0.1.3
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/dist/core.js +16 -4
- package/dist/web.js +52 -12
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -161,7 +161,7 @@ function stateGetterGet( target, prop ) {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
if ( prop === Symbol.toPrimitive )
|
|
164
|
-
throw new
|
|
164
|
+
throw new TypeError( 'Using a state getter as a primitive value is not allowed' );
|
|
165
165
|
|
|
166
166
|
return createChildStateGetterProxy( target, prop );
|
|
167
167
|
}
|
|
@@ -329,8 +329,8 @@ function computedGetterGet( target, prop ) {
|
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
if ( prop
|
|
333
|
-
throw new
|
|
332
|
+
if ( prop === Symbol.toPrimitive )
|
|
333
|
+
throw new TypeError( 'Using a computed getter as a primitive value is not allowed' );
|
|
334
334
|
|
|
335
335
|
return createChildComputedProxy( target, prop );
|
|
336
336
|
}
|
|
@@ -623,4 +623,16 @@ function transform( value, callback ) {
|
|
|
623
623
|
return callback( value );
|
|
624
624
|
}
|
|
625
625
|
|
|
626
|
-
|
|
626
|
+
function get( value ) {
|
|
627
|
+
if ( typeof value == 'function' )
|
|
628
|
+
return value();
|
|
629
|
+
return value;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function getter( value ) {
|
|
633
|
+
if ( typeof value == 'function' )
|
|
634
|
+
return value;
|
|
635
|
+
return constant( value );
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export { computed, constant, destroyScope, effect, get, getter, mutate, reactive, schedule, state, transform, watch, withScope };
|
package/dist/web.js
CHANGED
|
@@ -43,6 +43,7 @@ function createContext( parent ) {
|
|
|
43
43
|
scope: [],
|
|
44
44
|
mount: null,
|
|
45
45
|
destroy: null,
|
|
46
|
+
refs: null,
|
|
46
47
|
services: null,
|
|
47
48
|
};
|
|
48
49
|
}
|
|
@@ -94,12 +95,27 @@ function onDestroy( callback ) {
|
|
|
94
95
|
current.destroy.push( callback );
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
function createRef( callback, element ) {
|
|
99
|
+
if ( current != null ) {
|
|
100
|
+
if ( current.refs == null )
|
|
101
|
+
current.refs = [];
|
|
102
|
+
current.refs.push( { callback, element } );
|
|
103
|
+
} else {
|
|
104
|
+
callback( element );
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
97
108
|
function mountContext( context ) {
|
|
98
109
|
if ( context.children != null ) {
|
|
99
110
|
for ( const child of context.children )
|
|
100
111
|
mountContext( child );
|
|
101
112
|
}
|
|
102
113
|
|
|
114
|
+
if ( context.refs != null ) {
|
|
115
|
+
for ( const ref of context.refs )
|
|
116
|
+
ref.callback( ref.element );
|
|
117
|
+
}
|
|
118
|
+
|
|
103
119
|
if ( context.mount != null ) {
|
|
104
120
|
for ( const callback of context.mount )
|
|
105
121
|
callback();
|
|
@@ -113,7 +129,13 @@ function destroyContext( context ) {
|
|
|
113
129
|
context.destroy = null;
|
|
114
130
|
}
|
|
115
131
|
|
|
116
|
-
context.
|
|
132
|
+
context.mount = null;
|
|
133
|
+
|
|
134
|
+
if ( context.refs != null ) {
|
|
135
|
+
for ( const ref of context.refs )
|
|
136
|
+
ref.callback( null );
|
|
137
|
+
context.refs = null;
|
|
138
|
+
}
|
|
117
139
|
|
|
118
140
|
if ( context.scope.length > 0 ) {
|
|
119
141
|
destroyScope( context.scope );
|
|
@@ -125,6 +147,8 @@ function destroyContext( context ) {
|
|
|
125
147
|
destroyContext( child );
|
|
126
148
|
context.children = null;
|
|
127
149
|
}
|
|
150
|
+
|
|
151
|
+
context.services = null;
|
|
128
152
|
}
|
|
129
153
|
|
|
130
154
|
function provide( key, value ) {
|
|
@@ -150,15 +174,17 @@ function setClasses( element, classes ) {
|
|
|
150
174
|
if ( Array.isArray( value ) ) {
|
|
151
175
|
element.className = '';
|
|
152
176
|
element.classList.add( ...value );
|
|
153
|
-
} else {
|
|
177
|
+
} else if ( value != null ) {
|
|
154
178
|
element.className = value;
|
|
179
|
+
} else {
|
|
180
|
+
element.removeAttribute( 'class' );
|
|
155
181
|
}
|
|
156
182
|
} );
|
|
157
183
|
} else if ( isPlainObject( classes ) ) {
|
|
158
184
|
setClassesObject( element, classes );
|
|
159
185
|
} else if ( Array.isArray( classes ) ) {
|
|
160
186
|
setClassesArray( element, classes );
|
|
161
|
-
} else {
|
|
187
|
+
} else if ( classes != null ) {
|
|
162
188
|
element.className = classes;
|
|
163
189
|
}
|
|
164
190
|
}
|
|
@@ -197,7 +223,7 @@ function setClassesArray( element, classes ) {
|
|
|
197
223
|
} );
|
|
198
224
|
} else if ( isPlainObject( item ) ) {
|
|
199
225
|
setClassesObject( element, item );
|
|
200
|
-
} else {
|
|
226
|
+
} else if ( item != null ) {
|
|
201
227
|
element.classList.add( item );
|
|
202
228
|
}
|
|
203
229
|
}
|
|
@@ -626,13 +652,15 @@ function setStyles( element, styles ) {
|
|
|
626
652
|
element.style = '';
|
|
627
653
|
for ( const [ key, value ] of Object.entries( value ) )
|
|
628
654
|
setStyleProperty( element, key, value );
|
|
629
|
-
} else {
|
|
655
|
+
} else if ( value != null ) {
|
|
630
656
|
element.style = value;
|
|
657
|
+
} else {
|
|
658
|
+
element.removeAttribute( 'style' );
|
|
631
659
|
}
|
|
632
660
|
} );
|
|
633
661
|
} else if ( isPlainObject( styles ) ) {
|
|
634
662
|
setStylesObject( element, styles );
|
|
635
|
-
} else {
|
|
663
|
+
} else if ( styles != null ) {
|
|
636
664
|
element.style = styles;
|
|
637
665
|
}
|
|
638
666
|
}
|
|
@@ -640,13 +668,15 @@ function setStyles( element, styles ) {
|
|
|
640
668
|
function setStylesObject( element, styles ) {
|
|
641
669
|
for ( const [ key, value ] of Object.entries( styles ) ) {
|
|
642
670
|
if ( typeof value == 'function' )
|
|
643
|
-
reactive( value, value => element
|
|
671
|
+
reactive( value, value => setStyleProperty( element, key, value ) );
|
|
644
672
|
else
|
|
645
673
|
setStyleProperty( element, key, value );
|
|
646
674
|
}
|
|
647
675
|
}
|
|
648
676
|
|
|
649
677
|
function setStyleProperty( element, key, value ) {
|
|
678
|
+
if ( value == null )
|
|
679
|
+
value = '';
|
|
650
680
|
if ( key.startsWith( '--' ) )
|
|
651
681
|
element.style.setProperty( key, value );
|
|
652
682
|
else
|
|
@@ -690,13 +720,20 @@ function make( template ) {
|
|
|
690
720
|
|
|
691
721
|
const element = document.createElement( tag );
|
|
692
722
|
|
|
723
|
+
let properties = null;
|
|
724
|
+
|
|
693
725
|
let i = 1;
|
|
694
|
-
if ( i < template.length && isPlainObject( template[ i ] ) )
|
|
695
|
-
|
|
726
|
+
if ( i < template.length && isPlainObject( template[ i ] ) ) {
|
|
727
|
+
properties = template[ i++ ];
|
|
728
|
+
setElementProperties( element, properties );
|
|
729
|
+
}
|
|
696
730
|
|
|
697
731
|
for ( ; i < template.length; i++ )
|
|
698
732
|
appendNode( make( template[ i ] ), element );
|
|
699
733
|
|
|
734
|
+
if ( properties != null && 'value' in properties )
|
|
735
|
+
setElementProperty( element, 'value', properties.value );
|
|
736
|
+
|
|
700
737
|
return element;
|
|
701
738
|
}
|
|
702
739
|
|
|
@@ -728,7 +765,10 @@ function setElementProperties( element, properties ) {
|
|
|
728
765
|
setStyles( element, value );
|
|
729
766
|
break;
|
|
730
767
|
case 'ref':
|
|
731
|
-
|
|
768
|
+
createRef( value, element );
|
|
769
|
+
break;
|
|
770
|
+
case 'value':
|
|
771
|
+
// this property must be set after other properties are set and children are appended
|
|
732
772
|
break;
|
|
733
773
|
default:
|
|
734
774
|
setElementProperty( element, key, value );
|
|
@@ -742,9 +782,9 @@ function setElementProperty( element, key, value ) {
|
|
|
742
782
|
element.addEventListener( key.substring( 2 ), value );
|
|
743
783
|
} else if ( Properties.has( key ) ) {
|
|
744
784
|
if ( typeof value == 'function' )
|
|
745
|
-
reactive( value, value => element[ key ] = value );
|
|
785
|
+
reactive( value, value => element[ key ] = value != null ? value : '' );
|
|
746
786
|
else
|
|
747
|
-
element[ key ] = value;
|
|
787
|
+
element[ key ] = value != null ? value : '';
|
|
748
788
|
} else {
|
|
749
789
|
if ( typeof value == 'function' )
|
|
750
790
|
reactive( value, value => setElementAttribute( element, key, value ) );
|