Create an `attrs` proxy that lazily evaluates attribute strings as hyperscript in the parent scope
(componentEl)
| 96 | |
| 97 | /** Create an `attrs` proxy that lazily evaluates attribute strings as hyperscript in the parent scope */ |
| 98 | function createAttrs(componentEl) { |
| 99 | return new Proxy({ _hsSkipTracking: true }, { |
| 100 | get: function(_, prop) { |
| 101 | if (prop === '_hsSkipTracking') return true; |
| 102 | if (typeof prop !== 'string' || prop.startsWith('_')) return undefined; |
| 103 | var expr = parseArg(componentEl, prop); |
| 104 | if (!expr) return undefined; |
| 105 | var ctx = parentContext(componentEl); |
| 106 | return ctx ? expr.evaluate(ctx) : undefined; |
| 107 | }, |
| 108 | set: function(_, prop, value) { |
| 109 | var expr = parseArg(componentEl, prop); |
| 110 | if (!expr || !expr.set) return false; |
| 111 | var ctx = parentContext(componentEl); |
| 112 | if (!ctx) return false; |
| 113 | var lhs = {}; |
| 114 | if (expr.lhs) { |
| 115 | for (var key in expr.lhs) { |
| 116 | var e = expr.lhs[key]; |
| 117 | lhs[key] = e && e.evaluate ? e.evaluate(ctx) : e; |
| 118 | } |
| 119 | } |
| 120 | expr.set(ctx, lhs, value); |
| 121 | return true; |
| 122 | } |
| 123 | }); |
| 124 | } |
| 125 | |
| 126 | function registerComponent(templateEl, componentScript) { |
| 127 | const tagName = templateEl.getAttribute('component'); |
no test coverage detected