npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-resize-observer-service

v1.1.0

Published

Use a single ResizeObserver instance for better performance.

Downloads

73,962

Readme

ResizeObserverService

ResizeObserverService allows to use a single ResizeObserver instance for observing multiple elements to achieve better performance.

Why? Using multiple ResizeObserver instances can result in a noticeable performance penalty.

This service can be used to create any tools that can benefit from using a single centralized ResizeObserver. For example, you can create a modifier for handling Element's size changes: <div {{on-resize @onResize}} /> (the full example in the usage section).

It has good test coverage and is ready for production👍

Installation

ember install ember-resize-observer-service

If you need a ResizeObserver polyfill (caniuse.com):

ember install ember-resize-observer-polyfill

Usage

Service API

isEnabled

It is true if ResizeObserver is available, otherwise the service will ignore any method calls (e.g. in FastBoot environment).

observe(element, callback)

Initiates the observing of the provided element or adds an additional callback if the element is already observed.

Parameters

  • element HTMLElement - An element which size changes we want to observe.
  • callback function - A function that will be called whenever the size of the element changes. It is called with ResizeObserverEntry object for the given element.

unobserve(element [, callback ])

Ends the observing of the given element or just removes the provided callback.

It will unobserve the element if the callback is not provided or there are no more callbacks left for this element.

Parameters

  • element HTMLElement - An element to unobserve or remove callback for.
  • callback function? - A callback which will not respond to the element's size changes anymore.

clear()

Unobserve all observed elements.

Example

Here is a simplified example of {{on-resize}} modifier using the ResizeObserverService:

<div {{on-resize @onResize}}>
  Resize me
</div>
import Modifier from 'ember-modifier';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class OnResizeModifier extends Modifier {
  @service resizeObserver;

  didInstall() {
    this.resizeObserver.observe(this.element, this.handleResize);
  }

  willRemove() {
    this.resizeObserver.unobserve(this.element, this.handleResize);
  }

  @action
  handleResize(...args) {
    let [callback] = this.args.positional;
    callback(...args);
  }
}

Related addons

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v12 or above

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.