Socket
Socket
Sign inDemoInstall

ember-modifier

Package Overview
Dependencies
Maintainers
3
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-modifier

A library for writing Ember modifiers


Version published
Weekly downloads
125K
decreased by-1.69%
Maintainers
3
Weekly downloads
 
Created

What is ember-modifier?

The ember-modifier package provides a way to create reusable, composable, and encapsulated behavior for DOM elements in Ember.js applications. It allows developers to define custom modifiers that can be applied to elements in templates, enabling a clean separation of concerns and enhancing code maintainability.

What are ember-modifier's main functionalities?

Creating a Simple Modifier

This feature demonstrates how to create a simple modifier that focuses an input element when it is inserted into the DOM. The `focusInput` modifier is defined and then applied to an input element in a template.

```javascript
// app/modifiers/focus-input.js
import { modifier } from 'ember-modifier';

export default modifier(function focusInput(element) {
  element.focus();
});

// Usage in a template
<input {{focus-input}} />
```

Modifier with Arguments

This feature shows how to create a modifier that accepts arguments. The `setAttribute` modifier takes an attribute name and value as arguments and sets the attribute on the element.

```javascript
// app/modifiers/set-attribute.js
import { modifier } from 'ember-modifier';

export default modifier(function setAttribute(element, [attribute, value]) {
  element.setAttribute(attribute, value);
});

// Usage in a template
<div {{set-attribute 'data-test' 'example'}}></div>
```

Modifier with Cleanup

This feature illustrates how to create a modifier that adds an event listener to an element and cleans up the listener when the element is removed from the DOM. The `addEventListener` modifier adds a specified event listener and returns a cleanup function to remove the listener.

```javascript
// app/modifiers/add-event-listener.js
import { modifier } from 'ember-modifier';

export default modifier(function addEventListener(element, [event, handler]) {
  element.addEventListener(event, handler);

  return () => {
    element.removeEventListener(event, handler);
  };
});

// Usage in a template
<button {{add-event-listener 'click' this.handleClick}}>Click me</button>
```

Other packages similar to ember-modifier

Keywords

FAQs

Package last updated on 08 Apr 2022

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