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

ao-changeset-base

v0.0.8

Published

Component Mixin to validate and execute ember-changeset's under routes

Downloads

4

Readme

Ao-changeset-base

The AnchorOps changeset-base Mixin abstracts the application of changes and handling of changeset validation errors. An extending component is endowed with two actions onSave and onClose which will handle the corresponding 'positive' and 'negative' interactions in ember, leverage the changeset methods, and then continue bubbling those actions up the component chain.

##Making Hooks from Computed Properties

The onSave and onClose actions set properties on the extending component that Ember’s Computed Properties can observe. By optionally defining the following properties in each component, you dictate behavior for parts of the save and close routines.

##onSave ###beforeValidate

This property is invoked every time a save action is called regardless of a force. It is run before any validation is done on the changeset. The return value of this Computed Property is meaningful for how the onSave action continues:

Return Value | Significance

undefined | Continue through save action (this happens if no beforeValidate is present)

false | Stop the action from executing further

{force: false} | Fall through the rest of the Mixin’s save action and bubble save action, no force

{force: true} | Fall through the rest of the Mixin’s save action with force flag in first argument

###beforeSave This property is run after the changeset is validated (will not run if there are errors), and before it is pushed to the actual Ember Model. The return value of this Computed Property is meaningful, see the table of return values for beforeValidate.

###handleOnSaveErrors When an onSave action finds errors, it will set a property on the Component called changesetErrors, an Array of strings that represent the errors, then use this property to handle them. The return value of this property is not used.

Example of how these hooks might be used

   //client/app/components/mymodel/edit-page/component.js


    import Ember from 'ember'; 

    import ChangeSetMixin from 'client/mixins/changeset-base';


    export default Ember.Component.extend(ChangeSetMixin, { 

      beforeSave: Ember.computed(‘onSaveFired’, function(){

        this.set(‘mymodel.name’,this.get(‘mymodel.name).capitalize());

    }),

    handleOnSaveErrors: Ember.computed('changesetErrors', function(){

        this.get('changesetErrors').forEach(() => {

                this.display(err);

      }) 

    });

*The bold and underlined arguments for the Computed Properties are required for Ember to run these functions consistently. If you do not pass a property name for the Computed Property to observe it will execute the function once and use a cached version of it any time after that. By specifying ‘onSaveFired’ (reset every time by the Mixin) you are guaranteed the function will run each time. If you have other properties relevant to your specific implementation, you can use those as arguments just like with a regular Computed Property.

##onClose ###handleOnCloseErrors Use this property just like the handleOnSaveErrors hook. The validations will set the same property, changesetErrors, with the error collection. If handleOnCloseErrors is called, the isInvalid property of the Component is set to true. This is one failsafe so that a user does not close a page with edited data that isn’t valid

###isDirty This property is called after the validations, it is another failsafe so that a user does not leave a page with unsaved changes. If isInvalid or isDirty is set to true and there is no force flag present, the onClose action will not continue to bubble up. The two properties should be used to show markup that prompts the user to fix their errors or persist their unsaved changes.

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/.