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-onbeforeunload

v2.0.0

Published

An addon to conditionally prompt the user when transitioning between routes or closing the browser.

Downloads

23,218

Readme

ember-onbeforeunload

npm Version Build Status Ember Observer Score

An add-on to conditionally prompt the user when transitioning between routes or closing the browser.

Installation

This library is tested against Ember 1.13.x and Ember 2.x.

ember install ember-onbeforeunload

Usage

To get started, mix the ConfirmationMixin into your Ember.Route. By default, the user will be prompted beforeunload any time the model for the route hasDirtyAttributes (docs).

// app/routes/foo.js
import Ember from 'ember';
import ConfirmationMixin from 'ember-onbeforeunload/mixins/confirmation';

export default Ember.Route.extend(ConfirmationMixin, { });

Customization

This addon tries to provide sane defaults, but it also exposes all of the internals for customization.

Confirmation Message

You can customize the message displayed in the confirmation dialog by overriding the confirmationMessage property. You can either pass a hard-coded string, or use a function.

export default Ember.Route.extend(ConfirmationMixin, {
  confirmationMessage: 'Are you sure?',
});
export default Ember.Route.extend(ConfirmationMixin, {
  confirmationMessage(model) {
    return `Are you sure you want to unload ${model.name}?`;
  }
});
export default Ember.Route.extend(ConfirmationMixin, {
  i18n: service(), // see ember-i18n
  confirmationMessage() {
    return this.get('i18n').t('myTranslation');
  }
});

isPageDirty logic

If you do not sure Ember Data, or you have other logic to determine whether or not the page is dirty, you can override the isPageDirty method.

export default Ember.Route.extend(ConfirmationMixin, {
  isPageDirty(/* model */) {
    const isDirty = true; // your logic here
    return isDirty;
  }
});

Allow Dirty Transitions

By default, we allow navigating within the hierarchy of route you mix the ConfirmationMixin into. For example, navigating from myroute.index to myroute.index.subroute would not check isPageDirty. If you have other logic that determines when a dirty transition should be allowed, you can override shouldCheckIsPageDirty.

export default Ember.Route.extend(ConfirmationMixin, {
  shouldCheckIsPageDirty(transition) {
    const isChildRouteTransition = this._super(...arguments);

    if (transition.targetName === 'some-exempt-route') {
      return true;
    } else {
      return isChildRouteTransition;
    }
  }
});

onUnload logic

If you have some custom logic you'd like to execute when your route is unloaded, you can tie into the onUnload function. By default, this function is a no-op.

export default Ember.Route.extend(ConfirmationMixin, {
  onUnload() {
    // my custom unload logic
  }
});

Upgrading

This library underwent major API changes with version 1.0.0. For information on how to upgrade, please check out UPGRADING.md.

Issues

Found a bug? Please report it!

Development Instructions

Installing

  • git clone this repository
  • npm install
  • bower install

Linting

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

Running tests

  • ember test – Runs the test suite on the current Ember version
  • ember test --server – Runs the test suite in "watch mode"
  • npm test – Runs ember try:each to test your addon against multiple Ember versions

Running the dummy application

For more information on using ember-cli, visit http://www.ember-cli.com/.