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-data-autoreload

v0.0.4

Published

Add support for auto-reloading to Ember Data models.

Downloads

16

Readme

ember-data-autoreload

Build Status

ember-data-autoreload allows you to auto-reload models after some time has passed. It provides a mixin you can add to any Ember Data model:

import DS from 'ember-data';
import AutoReload from 'ember-data-autoreload';

export default DS.Model.extend(AutoReload, {
  // ...
});

Now you can call startAutoReloading() and stopAutoReloading() on this model to start or stop automatically reloading, respectively.

Configuration

ember-data-autoreload supports the following configuration options, all of which are set as properties on the model:

| Property | Possible values | Description | Default value | |---|---|---|--:| | autoReloadStrategy | 'fixed', 'incremental' | Determines how the delay between automatic reloads is determined. See below for a more complete explanation. | 'incremental' | | autoReloadDelay | Any number > 0 | The (initial) delay between automatic reloads. | 30000 | | autoReloadMaximumDelay | Any number > 0 and >= autoReloadDelay | The maximum delay between automatic reloads, if autoReloadStrategy === 'incremental' | 300000 | | autoReloadDelayGrowth | Any number > 1 | The rate with which the delay between automatic reloads grows, if autoReloadStrategy === 'incremental' | 2 |

Reload strategies

The autoReloadStrategy property is used to influence the delay between automatic reloads of your models. If this property is set to 'fixed', the model always reloads itself after a fixed interval, determined by the autoReloadDelay property.

If the property is set to 'incremental', the delay between automatic reloads will keep increasing every time the attributes on the model do not change. This will reduce the load on your API server if the model doesn't change often. As soon as the model does change in between reloads, the delay is reset. To increase or decrease the amount with which the delay grows, you can use the autoDelayGrowth property. Every time the model doesn't change, the new delay is calculated using previousDelay * autoReloadDelayGrowth.

Hooks

ember-data-autoreload provides three hooks into the auto reload process: shouldAutoReload, willAutoReload and didAutoReload. If you want to manually adjust the delay between auto reloads, or trigger side-effects, you can do so here. All hooks are promise-aware.

shouldAutoReload (snapshot)

This hook is called before a reload occurs. If you return false (or promise that resolves to false) from here, the model will not be reloaded until the next timeout period has passed. If you return true, the model will reload.

Parameters:

snapshot Ember Data Snapshot
A snapshot of the model before reloading.

willAutoReload (snapshot)

This hook is called right before this.reload is called on the model.

Parameters:

snapshot Ember Data Snapshot
A snapshot of the model before reloading.

didAutoReload (attributesChanged, newSnapshot, oldSnapshot)

This hook is called after this.reload is called on the model, and before the delay for the next automatic reload is scheduled.

Parameters:

attributesChanged Boolean
true if the model's attributes changed since before the reload, otherwise false.

newSnapshot Ember Data Snapshot
A snapshot of the model after reloading.

oldSnapshot Ember Data Snapshot
A snapshot of the model before reloading.