New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ember-bind-helper

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-bind-helper

Ember bind helper helps you bind functions in your templates.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61
decreased by-21.79%
Maintainers
2
Weekly downloads
 
Created
Source

Ember Bind Helper

CircleCI Ember Observer Score Code Climate dependencies Status

This addon provides a bind helper to bind a function to a context.

Installation

If you are running Ember 3.4+, just ember install ember-bind-helper.

If you are running a version older than 3.4, do ember install ember-bind-helper@0.3.2 instead.

Using bind

Let's say we want to call a method of an object when we click a function. We might think of doing the following:

<button onclick={{action myObject.myMethod}}>
  My Button
</button>

Sadly, this might not work as expected, given that the context would be the controller (twiddle). To solve this, you can use the bind helper:

<button onclick={{bind myObject.myMethod}}>
  My Button
</button>

This automagically sets the context to myObject. If the method were myObject.mySubobject.myMethod it would bind it to myObject.mySubobject and so on. The only exception to this rule is that if the last part of the chain before the method name is actions, it gets removed too:

<button onclick={{bind myObject.actions.myMethod}}>
  My Button
</button>

This sets the context to myObject. Normally it would have been myObject.actions but, given the last part is actions, ember-bind-helper removes that too leaving only myObject.

You can explicitly set the target by adding a named argument target:

<button onclick={{bind myObject.mySubobject.myMethod target=myObject}}>
  My Button
</button>

bind also passes any extra parameters to the binding function. Thus, when we click this button:

<button onclick={{bind myMethod 1 2 3 "caramba"}}>
  My Button
</button>

myMethod will receive 1, 2, 3 and "caramba" as arguments.

Linting

  • npm run lint:hbs
  • npm run lint:js
  • npm run lint:js -- --fix

License

This project is licensed under the MIT License.

Keywords

FAQs

Package last updated on 08 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc