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

Function _createExpressionSide

src/parsetree/features/bind.js:199–225  ·  view source on GitHub ↗

* Create a read/write side for a parsed expression (variable, attribute, class, etc).

(expr, target, feature, runtime)

Source from the content-addressed store, hash-verified

197 * Create a read/write side for a parsed expression (variable, attribute, class, etc).
198 */
199function _createExpressionSide(expr, target, feature, runtime) {
200 if (expr.type === "classRef") {
201 return {
202 read: function () {
203 runtime.resolveAttribute(target, "class");
204 return target.classList.contains(expr.className);
205 },
206 write: function (value) {
207 if (value) {
208 target.classList.add(expr.className);
209 } else {
210 target.classList.remove(expr.className);
211 }
212 }
213 };
214 }
215
216 return {
217 read: function () {
218 return expr.evaluate(runtime.makeContext(target, feature, target, null));
219 },
220 write: function (value) {
221 var ctx = runtime.makeContext(target, feature, target, null);
222 _assignTo(runtime, expr, ctx, value);
223 }
224 };
225}
226
227/**
228 * If either side wraps a form element, listen for the form's reset event

Callers 1

_resolveSideFunction · 0.70

Calls 5

_assignToFunction · 0.70
resolveAttributeMethod · 0.45
containsMethod · 0.45
evaluateMethod · 0.45
makeContextMethod · 0.45

Tested by

no test coverage detected