How to use the incremental-dom.attributes function in incremental-dom

To help you get started, we’ve selected a few incremental-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davidjamesstone / noide / client / patch.js View on Github external
var IncrementalDOM = require('incremental-dom')
var patch = IncrementalDOM.patch

// Fix up the element `value` attribute
IncrementalDOM.attributes.value = function (el, name, value) {
  el.value = value
}

module.exports = function (el, view, data) {
  var args = Array.prototype.slice.call(arguments)
  if (args.length <= 3) {
    patch(el, view, data)
  } else {
    patch(el, function () {
      view.apply(this, args.slice(2))
    })
  }
}
github davidjamesstone / superviews.js / client / index-old.js View on Github external
const IncrementalDOM = require('incremental-dom')
// TODO:
// SKIP
// EXTEND HTML
// No more checked={isChecked ? 'checked': null} => checked={isChecked} for boolean attributes
// Scope/this/data/model (spread?) between the view and customelement.
// Also event handlers need should not have to be redefined each patch
//   - In fact, dom level 1 events will *always* be redefined with superviews handler wrapper. Fix this.

IncrementalDOM.attributes.checked = function (el, name, value) {
  el.checked = !!value
}

IncrementalDOM.attributes.value = function (el, name, value) {
  el.value = value === null || typeof (value) === 'undefined' ? '' : value
}

const superviews = (Base, view, Controller, propsSchema, attrsSchema) => class extends Base {
  constructor () {
    super()
    const controller = new Controller(this, view, propsSchema, attrsSchema)
    this.controller = controller

    // Pass through props onto the controller
    if (propsSchema) {
      for (let prop in propsSchema) {
github davidjamesstone / superviews.js / client / index-old.js View on Github external
const IncrementalDOM = require('incremental-dom')
// TODO:
// SKIP
// EXTEND HTML
// No more checked={isChecked ? 'checked': null} => checked={isChecked} for boolean attributes
// Scope/this/data/model (spread?) between the view and customelement.
// Also event handlers need should not have to be redefined each patch
//   - In fact, dom level 1 events will *always* be redefined with superviews handler wrapper. Fix this.

IncrementalDOM.attributes.checked = function (el, name, value) {
  el.checked = !!value
}

IncrementalDOM.attributes.value = function (el, name, value) {
  el.value = value === null || typeof (value) === 'undefined' ? '' : value
}

const superviews = (Base, view, Controller, propsSchema, attrsSchema) => class extends Base {
  constructor () {
    super()
    const controller = new Controller(this, view, propsSchema, attrsSchema)
    this.controller = controller

    // Pass through props onto the controller
    if (propsSchema) {
      for (let prop in propsSchema) {
        Object.defineProperty(this, prop, {
          get: function () {
            return controller.props[prop]
          },
github justinfagnani / stampino / lib / stampino.js View on Github external
import * as idom from 'incremental-dom';
import { Parser } from 'polymer-expressions/parser';
import { EvalAstFactory } from 'polymer-expressions/eval';

let astFactory = new EvalAstFactory();

const toCamelCase = (s) => s.replace(/-(\w)/, (m) => m.p1.toUppercase());

idom.attributes.__default = function(element, name, value) {
  if (name.endsWith('$')) {
    name = name.substring(0, name.length - 1);
    element.setAttribute(name, value);
  } else {
    element[toCamelCase(name)] = value;
  }
};

export function getValue(value, model) {
  if (value.startsWith('{{') && value.endsWith('}}')) {
    let expression = value.substring(2, value.length - 2);
    let ast = new Parser(expression, astFactory).parse();
    return ast.evaluate(model);
  }
  if (value.startsWith('\\{{')) {
    return value.substring(1);