# ember-runloop-utils

> The default blueprint for ember-cli addons.

Latest version **0.0.4** (published 2016-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-runloop-utils
pnpm add ember-runloop-utils
yarn add ember-runloop-utils
bun add ember-runloop-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2016-06-17 |
| First published | 2016-06-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Maintainers | stefanpenner |
| Keywords | ember-addon |

## Links

- npm: https://www.npmjs.com/package/ember-runloop-utils
- Repository: https://github.com/stefanpenner/ember-runloop-utils
- Homepage: https://github.com/stefanpenner/ember-runloop-utils#readme
- Issues: https://github.com/stefanpenner/ember-runloop-utils/issues
- npm.io page: https://npm.io/package/ember-runloop-utils

## Dependencies (2)

- [ember-weakmap](https://npm.io/package/ember-weakmap.md) 1.0.0
- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^5.1.6

## Recent versions

- 0.0.4 (latest) — 2016-06-17
- 0.0.3 — 2016-06-17
- 0.0.2 — 2016-06-14
- 0.0.1 — 2016-06-08

## README

# Ember-runloop-utils [![Build Status](https://travis-ci.org/stefanpenner/ember-runloop-utils.svg?branch=master)](https://travis-ci.org/stefanpenner/ember-runloop-utils)

Observers are hard to use, when possible we should avoid them see: [this video](https://www.youtube.com/watch?v=vvZEddrClAQ) if you are curious how.

#### Now sometimes, observers are required (but rarely):

* pushing change information away from ember (to d3, or jQuery or similar)
* thats more or less it

Unfortunately, even in this scenarios it can be quite tricky to write them correctly. 

#### Common Requirements (tricky to implement):

* schedule on the run-loop
* should fire once per run-loop queue flush
* should not fire if the object is `isDestroyed` or `isDestroying`
* sometimes should not fire if the object is no longer `inDOM`
 
#### Solution:

This library provides several helpers which aim to address the above issue. The goal is to have a shared, well tested implemention of `onceObserver` and `inDomObserver` macros.


```js
// For the DOM observer use-case
import inDOMObserver from 'ember-runloop-utils/in-dom-observer'
import Component from 'ember/component'

export default Component.extend({
  dataDidChange: inDOMObserver('data.[]', function() {
    // safely and efficiently invoke your wonderful D3 code
  })
})
```

```js
// For crappy reasons non inDOM use-cases
import inDOMObserver from 'ember-runloop-utils/in-dom-observer'
import Component from 'ember/component'

export default Service.extend({
  dataDidChange: onceObserver('data.[]', function() {
    // for some unknown and most likely poor reason create an observer that only flushes once per run-loop flush
    // in well factored code, this should essentially never happen instead:
    //  * use actions + invoke explicit methods
    //  * use computed properties
    // Why is stef so emo about this? go watch -> https://www.youtube.com/watch?v=vvZEddrClAQ
  })
});
```




## Installation

* `git clone` this repository
* `npm install`
* `bower install`

## Running

* `ember server`
* Visit your app at http://localhost:4200.

## Running Tests

* `npm test` (Runs `ember try:testall` to test your addon against multiple Ember versions)
* `ember test`
* `ember test --server`

## Building

* `ember build`

For more information on using ember-cli, visit [http://ember-cli.com/](http://ember-cli.com/).

---
_Source: https://npm.io/package/ember-runloop-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
