Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-modifier

Package Overview
Dependencies
Maintainers
4
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

  • 4.0.0-beta.1-unstable.0a11f76
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
143K
increased by8.13%
Maintainers
4
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 02 Dec 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