MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / createAttrs

Function createAttrs

src/ext/component.js:98–124  ·  view source on GitHub ↗

Create an `attrs` proxy that lazily evaluates attribute strings as hyperscript in the parent scope

(componentEl)

Source from the content-addressed store, hash-verified

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');

Callers 1

connectedCallbackMethod · 0.70

Calls 4

parseArgFunction · 0.70
parentContextFunction · 0.70
evaluateMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected