* Create a read/write side for a parsed expression (variable, attribute, class, etc).
(expr, target, feature, runtime)
| 197 | * Create a read/write side for a parsed expression (variable, attribute, class, etc). |
| 198 | */ |
| 199 | function _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 |
no test coverage detected