Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thefrontside/ember-let
Create variable bindings inside your handlebars templates
https://github.com/thefrontside/ember-let
binding ember ember-addon emberjs functional-programming handlebars javascript
Last synced: about 1 month ago
JSON representation
Create variable bindings inside your handlebars templates
- Host: GitHub
- URL: https://github.com/thefrontside/ember-let
- Owner: thefrontside
- License: mit
- Created: 2016-07-13T12:38:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-07T15:06:49.000Z (about 6 years ago)
- Last Synced: 2024-09-21T09:12:00.817Z (2 months ago)
- Topics: binding, ember, ember-addon, emberjs, functional-programming, handlebars, javascript
- Language: JavaScript
- Homepage:
- Size: 142 KB
- Stars: 52
- Watchers: 11
- Forks: 16
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ember-let
[![npm version](https://badge.fury.io/js/ember-let.svg)](https://badge.fury.io/js/ember-let)
[![Ember Observer Score](https://emberobserver.com/badges/ember-let.svg)](https://emberobserver.com/addons/ember-let)
[![Build Status](https://travis-ci.org/thefrontside/ember-let.svg?branch=master)](https://travis-ci.org/thefrontside/ember-let)`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**
```hbs
{{#let "abc" "123" as |first second|}}
{{/let}}
```
**Mix hashes and standalone values**
```hbs
{{#let (hash first="first" second="second") "third" as |hash standalone|}}
{{/let}}
```
**Bind a class instance returned from a helper**
```hbs
{{#let (boolean) as |bool|}}
{{bool.value}} - toggle
{{/let}}
```
**Inline use**
Note: requires Ember 2.0+ (ie. does not support 1.13)
```hbs
{{let greeting=(concat "hello " to)}}
{{greeting}} - Greet the world!
```
Inline let declarations are in scope until the parent element or block is closed, for example:
```hbs
{{#if person.isActive}}
{{let name=person.name}}
{{name}}
{{!-- The name binding is not accessible here... --}}
{{/if}}
{{!-- ...or here. -- }}
```
## Installation
* `git clone` this repository
* `npm install`
* `bower install`
## Running
* `ember server`
* Visit your app at http://localhost:4200.
## 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/](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.