@@ -11,11 +11,15 @@ const Path = (m => m.__esModule ? m.default : m)(require('./Path.js'));
1111const Transformer = ( m => m . __esModule ? m . default : m ) ( require ( './Transformer.js' ) ) ;
1212const { text} = require ( '../shared/easy-dom.js' ) ;
1313const { isArray, trim, WeakSet} = require ( '../shared/poorlyfills.js' ) ;
14- const { createFragment} = require ( '../shared/utils.js' ) ;
14+ const { createFragment, slice } = require ( '../shared/utils.js' ) ;
1515
1616const Promise = global . Promise ;
1717const components = new WeakSet ;
18- const slice = [ ] . slice ;
18+
19+ function Cache ( ) { }
20+ Cache . prototype = Object . create ( null ) ;
21+
22+ const asHTML = html => ( { html} ) ;
1923
2024const create = ( root , paths ) => {
2125 const updates = [ ] ;
@@ -67,9 +71,6 @@ const find = (node, paths, parts) => {
6771 }
6872} ;
6973
70- function Cache ( ) { }
71- Cache . prototype = Object . create ( null ) ;
72-
7374const findAttributes = ( node , paths , parts ) => {
7475 const cache = new Cache ;
7576 const attributes = node . attributes ;
@@ -90,6 +91,37 @@ const findAttributes = (node, paths, parts) => {
9091 }
9192} ;
9293
94+ const invokeAtDistance = ( value , callback ) => {
95+ callback ( value . placeholder ) ;
96+ if ( 'text' in value ) {
97+ Promise . resolve ( value . text ) . then ( String ) . then ( callback ) ;
98+ } else if ( 'any' in value ) {
99+ Promise . resolve ( value . any ) . then ( callback ) ;
100+ } else if ( 'html' in value ) {
101+ Promise . resolve ( value . html ) . then ( asHTML ) . then ( callback ) ;
102+ } else {
103+ Promise . resolve ( Transformer . invoke ( value , callback ) ) . then ( callback ) ;
104+ }
105+ } ;
106+
107+ const isNode_ish = value => 'ELEMENT_NODE' in value ;
108+ const isPromise_ish = value => value != null && 'then' in value ;
109+ const isSpecial = ( node , name ) => ! ( OWNER_SVG_ELEMENT in node ) && name in node ;
110+
111+ const optimist = ( aura , value ) => {
112+ let length = aura . length ;
113+ if ( value . length !== length ) {
114+ majinbuu ( aura , value , Aura . MAX_LIST_SIZE ) ;
115+ } else {
116+ for ( let i = 0 ; i < length -- ; i ++ ) {
117+ if ( aura [ length ] !== value [ length ] || aura [ i ] !== value [ i ] ) {
118+ majinbuu ( aura , value , Aura . MAX_LIST_SIZE ) ;
119+ return ;
120+ }
121+ }
122+ }
123+ } ;
124+
93125const setAnyContent = ( node , childNodes ) => {
94126 const aura = new Aura ( node , childNodes ) ;
95127 let oldValue ;
@@ -190,96 +222,61 @@ const setAnyContent = (node, childNodes) => {
190222 return anyContent ;
191223} ;
192224
193- const asHTML = html => ( { html} ) ;
194-
195- const isNode_ish = value => 'ELEMENT_NODE' in value ;
196- const isPromise_ish = value => value != null && 'then' in value ;
197-
198- const invokeAtDistance = ( value , callback ) => {
199- callback ( value . placeholder ) ;
200- if ( 'text' in value ) {
201- Promise . resolve ( value . text ) . then ( String ) . then ( callback ) ;
202- } else if ( 'any' in value ) {
203- Promise . resolve ( value . any ) . then ( callback ) ;
204- } else if ( 'html' in value ) {
205- Promise . resolve ( value . html ) . then ( asHTML ) . then ( callback ) ;
206- } else {
207- Promise . resolve ( Transformer . invoke ( value , callback ) ) . then ( callback ) ;
208- }
209- }
210-
211- const isSpecialAttribute = ( node , name ) =>
212- ! ( OWNER_SVG_ELEMENT in node ) && name in node ;
213- const setAttribute = ( attribute , name ) => {
214- const node = attribute . ownerElement ;
225+ const setAttribute = ( node , name ) => {
215226 const isData = name === 'data' ;
216- const isEvent = ! isData && / ^ o n / . test ( name ) ;
217- const isSpecial = isData ||
218- ( isSpecialAttribute ( node , name ) &&
219- ! SHOULD_USE_ATTRIBUTE . test ( name ) ) ;
220- let noOwner = isSpecial || isEvent ;
221- let oldValue , type ;
222- if ( isEvent ) {
223- type = name . slice ( 2 ) ;
227+ let oldValue ;
228+ if ( ! isData && / ^ o n / . test ( name ) ) {
229+ let type = name . slice ( 2 ) ;
224230 if ( type === CONNECTED || type === DISCONNECTED ) {
225231 components . add ( node ) ;
226232 }
227233 else if ( name . toLowerCase ( ) in node ) {
228234 type = type . toLowerCase ( ) ;
229235 }
230- }
231- if ( ! noOwner ) node . setAttributeNode ( attribute ) ;
232- return isEvent ?
233- newValue => {
236+ return newValue => {
234237 if ( oldValue !== newValue ) {
235238 if ( oldValue ) node . removeEventListener ( type , oldValue , false ) ;
236239 oldValue = newValue ;
237240 if ( newValue ) node . addEventListener ( type , newValue , false ) ;
238241 }
239- } :
240- ( isSpecial ?
241- newValue => {
242- if ( oldValue !== newValue ) {
243- oldValue = newValue ;
244- if ( node [ name ] !== newValue ) {
245- node [ name ] = newValue ;
246- }
242+ } ;
243+ } else if ( isData || (
244+ isSpecial ( node , name ) &&
245+ ! SHOULD_USE_ATTRIBUTE . test ( name )
246+ ) ) {
247+ return newValue => {
248+ if ( oldValue !== newValue ) {
249+ oldValue = newValue ;
250+ if ( node [ name ] !== newValue ) {
251+ node [ name ] = newValue ;
247252 }
248- } :
249- newValue => {
250- if ( oldValue !== newValue ) {
251- oldValue = newValue ;
252- if ( attribute . value !== newValue ) {
253- if ( newValue == null ) {
254- if ( ! noOwner ) {
255- noOwner = true ;
256- node . removeAttributeNode ( attribute ) ;
257- }
258- } else {
259- attribute . value = newValue ;
260- if ( noOwner ) {
261- noOwner = false ;
262- node . setAttributeNode ( attribute ) ;
263- }
253+ }
254+ } ;
255+ } else {
256+ let noOwner = false ;
257+ const attribute = node . ownerDocument . createAttributeNode ( name ) ;
258+ node . setAttributeNode ( attribute ) ;
259+ return newValue => {
260+ if ( oldValue !== newValue ) {
261+ oldValue = newValue ;
262+ if ( attribute . value !== newValue ) {
263+ if ( newValue == null ) {
264+ if ( ! noOwner ) {
265+ noOwner = true ;
266+ node . removeAttributeNode ( attribute ) ;
267+ }
268+ } else {
269+ attribute . value = newValue ;
270+ if ( noOwner ) {
271+ noOwner = false ;
272+ node . setAttributeNode ( attribute ) ;
264273 }
265274 }
266275 }
267- } ) ;
268- } ;
269-
270- const optimist = ( aura , value ) => {
271- let length = aura . length ;
272- if ( value . length !== length ) {
273- majinbuu ( aura , value , Aura . MAX_LIST_SIZE ) ;
274- } else {
275- for ( let i = 0 ; i < length -- ; i ++ ) {
276- if ( aura [ length ] !== value [ length ] || aura [ i ] !== value [ i ] ) {
277- majinbuu ( aura , value , Aura . MAX_LIST_SIZE ) ;
278- return ;
279276 }
280- }
277+ } ;
281278 }
282- }
279+ } ;
283280
284281const setTextContent = node => {
285282 let oldValue ;
0 commit comments