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-cli-stained-by-children

v0.4.0

Published

The default blueprint for ember-cli addons.

Downloads

55

Readme

This addon grew into a collection of mixins. The addon is named after the first of those mixins. Thus, the name doesn't reflect the capabilities of the addon very well, but i decided not to change it. -- @lolmaus

Installation

You must have Ember CLI installed in your system and your project must be Ember CLI-driven.

In your project folder:

ember install:addon ember-cli-stained-by-children

The mixins

stained-by-children

This mixin modifies the isDirty property of a model, making it respect the dirtiness of its children.

Usage

In your parent model:

  1. Import stained-by-children/stained-by-children (path has changed in 0.3!).
  2. Extend your model with the mixin.
  3. Apply stains: true to the relationships whose dirtiness should affect your model's dirtiness:
// app/models/foo.js

import DS from 'ember-data';
import StainedByChildrenMixin from 'stained-by-children/stained-by-children';

Foo = DS.Model.extend( StainedByChildrenMixin, {
  bars: DS.hasMany   ( 'bar',  {stains: true} )
  baz:  DS.belongsTo ( 'baz'                  )
  quux: DS.belongsTo ( 'quux', {stains: true} )
});

export default Foo;

In the above example, a foo will be marked dirty, whenever its quux or any of its bars become dirty. The baz will not affect foo's dirtiness because the respective relationship is not flagged with stains: true.

How it works

The mixin creates an areChildrenDirty computed property property bound to <rels>[email protected], where <rels> are all its relationships marked with stains: true. The property is true when any staining child is dirty.

The mixin also modifies the isDirty property. Originally, isDirty is merely an alias to currentState.isDirty. After you import the mixin, isDirty will compute to

this.get('currentState.isDirty') || this.get('areChildrenDirty')

:warning: Warning!

  • Circular references are not supported!

    If you define two models staining/cleaning each other, your app will be unable to start.

  • This mixin only reflects the dirtiness of children. It does not make the parent record dirty when the relationship content changes. That is, when a non-dirty child is replaced with another non-dirty child, the result is non-dirty. :(

    I struggle to figure out how to address this use case. The tricky part simply creating a parent record with children already triggers observers for child and children.[]. If you can think of a way to overcome this, chime into the discussion.

clean-embedded-children

DS.EmbeddedRecordsMixin has a known issue: when you save a parent record, embedded children remain dirty. This is a bummer, especially when you use stained-by-children.

You can resolve this issue with clean-embedded-children!

Usage

In your parent model:

  1. Import stained-by-children/clean-embedded-children.
  2. Extend your model with the mixin.
  3. Apply embeddedChild: true to the relationships who should become clean when this record is saved.

The example below combines both mixins:

// app/models/foo.js

import DS from 'ember-data';
import StainedByChildrenMixin from 'stained-by-children/stained-by-children';
import CleanEmbeddedChildrenMixin from 'stained-by-children/clean-embedded-children';

Foo = DS.Model.extend( StainedByChildrenMixin, CleanEmbeddedChildrenMixin, {
  bars: DS.hasMany   ( 'bar',  {stains: true, embeddedChild: true} )
  baz:  DS.belongsTo ( 'baz'                                       )
  quux: DS.belongsTo ( 'quux', {stains: true, embeddedChild: true} )
});

export default Foo;

Cleaning children can be done recursively. Just user the mixin on child model as well as parent model, and saving a parent record will result in cleaning both its children and children's children.

License

MIT

Credit

Snapped together by Andrey Mikhaylov (lolmaus) https://github.com/lolmaus