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-mirage-nested

v2.0.1

Published

The default blueprint for ember-cli addons.

Downloads

52

Readme

ember-cli-mirage-nested

This addon does two different things at the moment and will be soon split into ember-cli-mirage-scenario-chaining and ember-cli-mirage-gui

Demo

https://britishgas-engineering.github.io/ember-cli-mirage-nested

1) ember-cli-mirage-scenario-chaining

Define your Mirage scenario with nested syntax such as:

server.create('parent').hasOne('child').hasOne('grandChild');

Features

We created a few very useful methods to be used on Mirage models (once they are extended using our mixin), allowing to easily create scenarii:

  • hasOne : the parent model instance has one and only one child model instance (given a relationship parent to child has been set). example:
//mirage/scenarios/default.js
const parent = server.create('parent');
const child = parent.hasOne('child', {propertyOfTheChild: value})
parent.child === child //true
  • hasMulti : the parent model instance has multiple child model instance (given a hasMany relationship parent to child has been set). example:
//mirage/scenarios/default.js
const parent = server.create('parent');
const children = parent.hasMulti('children', 3, {propertyThatAllTheChildrenWillHave: value})
parent.children.models === children //true
  • hasNo : the parent model instance has no child model instance (given a relationship parent to child has been set). example:
//mirage/scenarios/default.js
const parent = server.create('parent');
parent.hasNo('child');
parent.child === null //true
  • In addition we added a default method available for each Mirage model, which will be run whenever a new model instance is created - similar to an init method, this allows to create default children relationships on model creation

Usage

Extend your Mirage models from the bg-model-mixin in this addon, for example:

//mirage/models/bg-model.js
import { Model } from 'ember-cli-mirage';
import EmberCliMirageNestedMixin from  'ember-cli-mirage-nested/mirage/bg-model-mixin';

export default Model.extend(EmberCliMirageNestedMixin);
//mirage/models/parent.js
import BgModel from './bg-model';
import { hasMany, belongsTo } from 'ember-cli-mirage';

export default BgModel.extend({
  childrenAssociations: ['children'],//will be destroyed when this model instance is destroyed
  children: hasMany('child', {inverse: 'parent'})
  default() {//will be run every time a new "parent" model instance is created
    const children = this.hasMulti('children', 3);
  }
});

2) ember-cli-mirage-gui

This addon adds some methods in Mirage models allowing to create a Graphical User Interface in your app to easily create Mirage scenario, like the one in our demo.

Only alpha version for now (components for the GUI are in the dummy app of this addon), documentation / wiki is in progress.

Set all the options for this functionality in a forGUI object in your model

//mirage/models/parent.js
import BgModel from './bg-model';
import { hasMany, belongsTo } from 'ember-cli-mirage';

export default BgModel.extend({
  childrenAssociations: ['children'],  
  children: hasMany('child', {inverse: 'parent'}),
  forGUI: {
    allowChangeNbAssociations: ['children'],//allows changing the associations in the GUI
    flags: [{
      name: 'title',//allow to change the "title" attribute of this model in the GUI
      displayName: 'titleGui',// (optional) allows to show a different name for the attribute in the GUI
      options: [//set the options for the title
        'The title attribute of this model is set on init in the "default" hook of the model.',
        'Also, this model has two children by default.'
      ],
      method: 'updateTitle'//(optional) if set, then you will call this method in the model when changing the GUI instead of changing the attribute
    }]
  },
  default() {//will be run every time a new "parent" model instance is created
    const children = this.hasMulti('children', 3);
  }
});