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

@airglow/prefab-form-saga

v0.8.0

Published

A saga to hook up prefab-forms to redux for saving

Downloads

61

Readme

Prefab-Form-Saga

A saga written to handle Prefab Form submits. Out of the gates, Prefab Form provides a form submit action that you can wire into your form or buttons. That event doesn't automatically get picked up though. This provides a saga that will validate your form and send off an action accordingly.

Requirements

In order for this saga to work, you need to be using Redux Saga. The most common setup in Airglow is to have the following:

Getting Started

To initialize this saga within Airglow, you'll need to do the following:

import saga from '@airglow/prefab-form-saga';

const App = () => (
  <Airglow
    store={ReduxStore}
    plugins={plugins}
    bootstrap={{
      sagas: saga
    }}
  >
    <MainContainer />
  </Airglow>
);

Configuring Your Form

The basic Prefab Form allows for custom configuration options out of the box. Our saga leverages this and allows you to add the following options:

| Config Key | Description | | ----------- | ----------- | | invalidAction | An action to dispatch if the form is invalid. | | invalidActions | An array of actions to dispatch if the form is invalid. | | validAction | An action to dispatch if the form is valid. | | validActions | An array of actions to dispatch if the form is valid. | | successAction | An action to dispatch if a save operation succeeds. | | successActions | An array of actions to dispatch if a save operation succeeds. | | errorActions | An action to dispatch if a save operation failes. | | errorActions | An array of actions to dispatch if a save operation fails. | | submitSaga | A custom redux saga to trigger if the form is valid | | resetOnSuccess | A boolean to determine if the form resetActions should trigger after success. Default is true |

Please note, this saga doesn't actually run any save operations. It simply validates and calls the invalid or valid actions accordingly. It is up to you to respond to the validAction(s) or provide a submitSaga. From there, you must perform the save and trigger the successActions and errorActions accordingly.

Another thing to note: the success actions will automatically trigger a reset of all the form fields.

Example Form Prefab

import prefab from '@airglow/prefab';
import '@airglow/prefab-form';
import { showError, submitForm, showSuccess } from 'actions';

export const prefabs = prefab({
  pizzaOrder: {
    type: 'value'
    fields: {
      size: { required: true },
      quantity: { fieldType: 'number', required: true, min: 1, max: 99 },
      toppings: {  }
    },
    invalidAction: showError,
    validAction: submitForm,
    successAction: showSuccess,
    errorAction: showError
  }
});