Code Monkey home page Code Monkey logo

ember-let's Introduction

ember-let

npm version Ember Observer Score Build Status

ember-let is an addon for binding variables to template contexts in Ember. It behaves much like the with helper, but lets you bind an arbitrary number of variables, including standalone values, hashes, and class instances. However, unlike with, the let helper will yield its block even if the bound values are undefined, null, or []. This has the benefit of allowing the user to treat the block values as true variable bindings rather than simply aliases to existing values.

See examples below:

Bind basic values

{{#let "abc" "123" as |first second|}}
  <li>{{first}}</li>
  <li>{{second}}</li>
{{/let}}

Mix hashes and standalone values

{{#let (hash first="first" second="second") "third" as |hash standalone|}}
  <li>{{hash.first}}</li>
  <li>{{hash.second}}</li>
  <li>{{standalone}}</li>
{{/let}}

Bind a class instance returned from a helper

{{#let (boolean) as |bool|}}
  {{bool.value}} - <button onClick={{action bool.toggle}}>toggle</button>
{{/let}}

Inline use Note: requires Ember 2.0+ (ie. does not support 1.13)

{{let greeting=(concat "hello " to)}}
{{greeting}} - <button {{action (action (mut to) "world")}}>Greet the world!</button>  

Inline let declarations are in scope until the parent element or block is closed, for example:

{{#if person.isActive}}
  <div>
    {{let name=person.name}}
    <span>{{name}}</span>
  </div>
  {{!-- The name binding is not accessible here... --}}
{{/if}}
{{!-- ...or here. -- }}

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • npm test (Runs ember try:testall to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://ember-cli.com/.

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms, which can be found in the CODE_OF_CONDUCT.md file in this repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.