function generateAccessor(key, value) {
  const formatter = PROPERTY_FORMATTERS[key] || IDENTITY;
  // ex: key = 'fill', value = {defaut: 'red', hover: 'blue'}
  // valueMap => {defaut: [255, 0, 0], hover: [0, 0, 255]}
  const valueMap = Object.keys(value).reduce((res, key) => {
    res[key] = value[key];
    return res;
  }, {});

  return node => {
    const statefulValue = valueMap[node.state];
    if (!node.state || typeof statefulValue === 'undefined') {
      return valueMap['default'] || DEFAULT_STYLES[key];
    }
    // else has stateful value
    // check if the value is a function
    if (typeof statefulValue === 'function') {
      return formatter(statefulValue(node));
    }
    // or just a plain value
    return formatter(statefulValue);
  };
}
// code generation: generate a function as a layer accessor
code generation: generate a function as a layer accessor
code generation : generate a function as a layer accessor
function generateAccessor(key, value) {
  const formatter = PROPERTY_FORMATTERS[key] || IDENTITY;
  const valueMap = Object.keys(value).reduce((res, key) => {
    res[key] = value[key];
    return res;
  }, {});
  return node => {
    const statefulValue = valueMap[node.state];
    if (!node.state || typeof statefulValue === 'undefined') {
      return valueMap['default'] || DEFAULT_STYLES[key];
    }
    if (typeof statefulValue === 'function') {
      return formatter(statefulValue(node));
    }
    return formatter(statefulValue);
  };
}
function generateAccessor ( key , value ) { const formatter = PROPERTY_FORMATTERS [ key ] || IDENTITY ; const valueMap = Object . keys ( value ) . reduce ( ( res , key ) => { res [ key ] = value [ key ] ; return res ; } , { } ) ; return node => { const statefulValue = valueMap [ node . state ] ; if ( ! node . state || typeof statefulValue === 'undefined' ) { return valueMap [ 'default' ] || DEFAULT_STYLES [ key ] ; } if ( typeof statefulValue === 'function' ) { return formatter ( statefulValue ( node ) ) ; } return formatter ( statefulValue ) ; } ; }
code generation: generate a function as a layer accessor
code generation : generate a function as a layer accessor
// ex: key = 'fill', value = {defaut: 'red', hover: 'blue'} // valueMap => {defaut: [255, 0, 0], hover: [0, 0, 255]} // else has stateful value // check if the value is a function // or just a plain value