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

gr-forms

v0.0.3

Published

reactive forms library that introduces observables based on the form value changes that can be used in order to control the form fields

Downloads

4

Readme

GrForms

A reactive form based library that serves as a very simple overhead in order to build reactive forms.

Form builder

the main goal provided by this library is to assure the ability of creating an angular form using a new concept. The concept that we introduce here is very simple: we provide the ability to use form value changes observables, pipe them in all possible scenarios, and then pass down these observables to the form constructor (builder in our case).

This sounds a bit complicated right ?. well it is a little bit. But when you think about it in a different way, it's not.

let's take the usual way of creating forms. call the constructor, create the form instance, then you can subscribe or pipe the valueChange observable to validate or invalidate some fields, to disable or enable some inputs based on some other form values, or even to override some field based on another. this will result in creating so many subscriptions, so much non needed code etc.. (we all hate that)

Now let's imagine we magically have access to that value changes observable even before the form is created. :smirk: we can pipe it into some async validators, and the pass these validators to the constructor the usual way, that would mean we have the ability to validate fields based on other fields without making any subscriptions or non needed code, just pipe it and pass it down. same thing goes for fields enabling and disabling, but this is a new constructor property introduced by this library, similar to angular asyncValidators you can now pass an observable that will be used to automatically enable or disable any field, and based on our magically provided value changes observable, you can also pipe it and pass it to the constructor. And the same this is for value overriding, also newly introduced behavior that makes it possible to set a control value based on an observable.

As we see this will make it possible to define all form fields, groups and arrays interactions defined even before the form itself is created, then there will be no need to make any kind of subscription to do some logic. All will be just defined beforehand.

As you probably noticed there is a lot of piping going on. however we now provide a logic to auto pipe everything. for anybody familiar with ngRx we introduced the same concept know as selectors. this means that you just define the actual logic in a callback, and based on that we create an observable with the return value of your logic callback.

all of this is defined in single form builder class named GrBuilder.

public methods:
  • createSelector<T>(projector: (value, form?) => T) => Observable<T>
    • a callback to create a selector, takes a projector function that accepts the latest form value and the form itself as an optional parameter, and returns any value based on the required logic implemented.`
    • returns an observable that only emits when the return value of the projector function changes.
    • can and should be used to create selectors before building the form in order to create validators, form disablers and value overriders.
  • buildForm(dataModel: GrAbstract)
    • takes a data model in order to create the actual form. data model should be built using the provided build-model classes whitch are:

Build Models

these 4 classes are basically a mirror of the angular provided controls except that they are used to build the angular form controls. these classes take our previously mentioned selectors in order to use for building the controls

  • GrControl: used in order to build a FormControl.
  • GrGroup: used in order to build a FormGroup.
  • GrArray: used in order to build a FormArray.

Each of these Build Models takes an optional options object as a construction parameter

Options {
  validators?: FormValidators;
  asyncValidators?: AsyncFormValidators;
  disabler?: Observable<FormDisable>;
  valueOverrider?: Observable<ValueOverride>;
}

Typed Forms Classes

  • GrFormGroup<C, V>
    • A class that extends angular FormGroup and provides the possibility to get a type safe value and controls objects.
    • you can get a type safe controls using grControls and a type safe value using grValue
    • everything provided by angular FormGroup is still usable since this is just an extension.
  • GrFormArray
    • A class that extends angular FormArray and provides the possiblity to get a typeSafe value and controls objects.
    • you can get a type safe controls using grControls and a type safe value using grValue
    • everything provided by angular FormArray is still usable since this is just an extension.