项目作者: nheise

项目描述 :
Utility for Mithril creating attributes
高级语言: JavaScript
项目地址: git://github.com/nheise/mithril-util-attributes.git
创建时间: 2017-04-20T11:03:09Z
项目社区:https://github.com/nheise/mithril-util-attributes

开源协议:MIT License

下载


mithril-util-attributes

Usage | API

Utility for Mithril creating attributes

Usage

Basic Usage

First create the builder, use it and get the attributes to use them in the mithril function.

  1. var m = require('mithril')
  2. var ma = require('mithril-util-attributes')
  3. var div = m( "div", ma().id( "0" ).get() )

Create CSS Classes

  1. var div = m( "div", ma().css( "highlight", ctrl.isHighlighted(), "bold", ctrl.isBold(), "italic", ctrl.isItalic() ).get() )
  2. // when ctrl.isHighlighted() == true
  3. // when ctrl.isBold() == false
  4. // when ctrl.isItalic() == true
  5. // will create { 'class': 'highlight italic' }

Create Event bi-directional binding

  1. m( "input", ma().name( "description" ).value( "initialValue" ).oninput( ctrl.setDescription ).get() )

API

Create the Builder

Builder ma( [Object givenAttributes] )

Creates a new instance of the builder. If you have attributes already, you can them handover via optional parameter.

Builder

Builder builder.new( [Object givenAttributes] )

Creates a new instance of the builder. If you have attributes already, you can them handover via optional parameter.


Object builder.get()

Creates the attribute object.


Builder builder.css( String cssClassName, Boolean useit [,String cssClassName, Boolean useIt ] )

Can be invoked as often you like.
The last class of two or more identical class strings will win.


Builder builder.id( String id )


Builder builder.key( String key )


Builder builder.onclick( Function callback )


Builder builder.value( String value )


Builder builder.oninput( Function callback [, Boolean useMithrilWithAttrFunction [, Object thisArg ]] )


Builder builder.onchange( Function callback [, Boolean useMithrilWithAttrFunction [, Object thisArg ]] )


Builder builder.withAttr( String attrName, String event, Object initialValue, Function callback [, Object thisArg ] )

This will invoke internally:

  1. attrs[attrName] = initialValue
  2. attrs[event] = m.withAttr( attrName, callback, thisArg )

Builder builder.set( String key, Any value )

Set any attribute you like.