@webqit/oohtml 3.1.7 → 3.1.8

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.
@@ -50,9 +50,15 @@ function realtime( config ) {
50
50
  }
51
51
 
52
52
  function createDynamicScope( config, root ) {
53
- const { webqit: { Observer, DOMBindingsContext } } = this;
53
+ const { webqit: { realdom, Observer, DOMBindingsContext } } = this;
54
54
  if ( _( root ).has( 'data-binding' ) ) return _( root ).get( 'data-binding' );
55
55
  const scope = Object.create( null ), abortController = new AbortController;
56
+ scope[ '$exec__' ] = ( target, prop, ...args ) => {
57
+ realdom.schedule( 'write', () => target[ prop ]( ...args ) );
58
+ };
59
+ scope[ '$assign__' ] = ( target, prop, val ) => {
60
+ realdom.schedule( 'write', () => (target[ prop ] = val) );
61
+ };
56
62
  Observer.intercept( scope, {
57
63
  get: ( e, recieved, next ) => {
58
64
  if ( !( e.key in scope ) ) {
@@ -130,10 +136,10 @@ const discreteParseCache = new Map;
130
136
  function compileDiscreteBindings( config, str ) {
131
137
  if ( discreteParseCache.has( str ) ) return discreteParseCache.get( str );
132
138
  let source = `let content = ((${ str }) ?? '') + '';`;
133
- source += `this.nodeValue = content;`;
134
- source += `if ( this.$oohtml_internal_databinding_anchorNode ) { this.$oohtml_internal_databinding_anchorNode.nodeValue = "${ config.tokens.tagStart }${ escDouble( str ) }${ config.tokens.stateStart }" + content.length + "${ config.tokens.stateEnd } ${ config.tokens.tagEnd }"; }`;
135
- const { webqit: { QuantumAsyncScript } } = this;
136
- const compiled = new QuantumAsyncScript( source );
139
+ source += `$assign__(this, 'nodeValue', content);`;
140
+ source += `if ( this.$oohtml_internal_databinding_anchorNode ) { $assign__(this.$oohtml_internal_databinding_anchorNode, 'nodeValue', "${ config.tokens.tagStart }${ escDouble( str ) }${ config.tokens.stateStart }" + content.length + "${ config.tokens.stateEnd } ${ config.tokens.tagEnd }"); }`;
141
+ const { webqit: { QuantumModule } } = this;
142
+ const compiled = new QuantumModule( source );
137
143
  discreteParseCache.set( str, compiled );
138
144
  return compiled;
139
145
  }
@@ -157,19 +163,19 @@ function compileInlineBindings( config, str ) {
157
163
  const directive = left[ 0 ], param = left.slice( 1 ).trim();
158
164
  const arg = `(${ right })`, $arg = `(${ arg } ?? '')`;
159
165
  if ( directive === '&' ) {
160
- if ( param.startsWith( '--' ) ) return `this.style.setProperty("${ escDouble( param ) }", ${ $arg });`;
161
- return `this.style["${ escDouble( param ) }"] = ${ $arg };`;
166
+ if ( param.startsWith( '--' ) ) return `$exec__(this.style, 'setProperty', "${ escDouble( param ) }", ${ $arg });`;
167
+ return `$assign__(this.style, "${ escDouble( param ) }", ${ $arg });`;
162
168
  }
163
- if ( directive === '%' ) return `this.classList.toggle("${ escDouble( param ) }", !!${ arg });`;
169
+ if ( directive === '%' ) return `$exec__(this.classList, 'toggle', "${ escDouble( param ) }", !!${ arg });`;
164
170
  if ( directive === '~' ) {
165
- if ( param.startsWith( '?' ) ) return `this.toggleAttribute("${ escDouble( param.substring( 1 ).trim() ) }", !!${ arg });`;
166
- return `this.setAttribute("${ escDouble( param ) }", ${ $arg });`;
171
+ if ( param.startsWith( '?' ) ) return `$exec__(this, 'toggleAttribute', "${ escDouble( param.substring( 1 ).trim() ) }", !!${ arg });`;
172
+ return `$exec__(this, 'setAttribute', "${ escDouble( param ) }", ${ $arg });`;
167
173
  }
168
174
  if ( directive === '@' ) {
169
175
  if ( validation[ param ] ) throw new Error( `Duplicate binding: ${ left }.` );
170
176
  validation[ param ] = true;
171
- if ( param === 'text' ) return `this.textContent = ${ $arg };`;
172
- if ( param === 'html' ) return `this.setHTML(${ $arg });`;
177
+ if ( param === 'text' ) return `$assign__(this, 'textContent', ${ $arg });`;
178
+ if ( param === 'html' ) return `$exec__(this, 'setHTML', ${ $arg });`;
173
179
  if ( param === 'items' ) {
174
180
  const [ iterationSpec, importSpec ] = splitOuter( right, '/' );
175
181
  if ( !importSpec ) throw new Error( `Invalid ${ directive }items spec: ${ str }; no import specifier.` );
@@ -200,13 +206,14 @@ function compileInlineBindings( config, str ) {
200
206
  let $itemNode__ = $existing__.get( $key___ );
201
207
  if ( $itemNode__ ) {
202
208
  $existing__.delete( $key___ );
209
+ $exec__($itemNode__, '${ config.BINDINGS_API.api.bind }', $itemBinding__ );
203
210
  } else {
204
211
  $itemNode__ = ( Array.isArray( $import__.value ) ? $import__.value[ 0 ] : ( $import__.value instanceof window.HTMLTemplateElement ? $import__.value.content.firstElementChild : $import__.value ) ).cloneNode( true );
205
212
  $itemNode__.setAttribute( "${ config.attr.itemIndex }", $key___ );
206
- this.appendChild( $itemNode__ );
213
+ $exec__($itemNode__, '${ config.BINDINGS_API.api.bind }', $itemBinding__ );
214
+ $exec__(this, 'appendChild', $itemNode__ );
207
215
  }
208
216
 
209
- $itemNode__.${ config.BINDINGS_API.api.bind }( $itemBinding__ );
210
217
  if ( ${ kind === 'in' ? `!( ${ production[ 0 ] } in $iteratee__ )` : `typeof ${ production[ 0 ] } === 'undefined'` } ) { $itemNode__.remove(); }
211
218
  }
212
219
  $existing__.forEach( x => x.remove() );
@@ -216,8 +223,8 @@ function compileInlineBindings( config, str ) {
216
223
  }
217
224
  if ( str.trim() ) throw new Error( `Invalid binding: ${ str }.` );
218
225
  } ).join( `\n` );
219
- const { webqit: { QuantumAsyncScript } } = this;
220
- const compiled = new QuantumAsyncScript( source );
226
+ const { webqit: { QuantumModule } } = this;
227
+ const compiled = new QuantumModule( source );
221
228
  inlineParseCache.set( str, compiled );
222
229
  return compiled;
223
230
  }