项目作者: lifeart

项目描述 :
Ember JS eval helper
高级语言: JavaScript
项目地址: git://github.com/lifeart/ember-eval-helper.git
创建时间: 2019-09-18T22:23:31Z
项目社区:https://github.com/lifeart/ember-eval-helper

开源协议:MIT License

下载


ember-eval-helper

This addon introduce e (eval) helper, to allow this syntax usage in templates:

  • this addont don’t use eval.
  1. <button {{action (e "alert") "Hello" target=(e "window") }}>
  2. onclick = window.alert("hello")
  3. </button>
  1. {{#let (e "{ projectName: 'Ember' }") as |project|}}
  2. <h2 id="title">{{project.projectName}}</h2>
  3. {{/let}}
  4. {{#each (e "[1,2,3,4]") as |item|}}
  5. Number: {{item}}
  6. {{/each}}

this scope access also supported, passing it as second argument

  1. export {
  2. name: "foo"
  3. }
  1. {{e 'this.name' this}}

Manual this context creation:

  1. <MyComponent
  2. @params={{
  3. e "this.onClick(this.foo, this.bar)"
  4. (hash
  5. onClick=(e "this.onClick.bind(this)" this)
  6. foo=@foo
  7. bar=(array 1 2 3)
  8. )
  9. }}
  10. ></MyComponent>

Sugar: Angle components tagged values will be autocompiled.

  1. // input
  2. <MyComponent @name="`this.realName()`" ></MyComponent>
  3. // output
  4. <MyComponent @name={{e 'this.realName()' this}}>

Compatibility

  • Ember.js v2.18 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

Installation

  1. ember install ember-eval-helper

Usage

  1. helper e(evalString = '', context = null)
  1. <Component @attr="`someTextToEval`" ></Component>

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.