rx-form-data
Minimal, Reactive Form data handling
- Fully written in Typescript
- Turns form into a signal of field values (user input & some metadata)
- Framework Agnostic
- Easy integration with any custom validation logic
- Super tiny with ZERO dependencies
Table of Contents
Install
npm install --save @metronlabs/rx-form-data
Then with a module bundler like rollup or webpack, use as you would anything else:
import RxFormData from "@metronlabs/rx-form-data";
const RxFormData = require("@metronlabs/rx-form-data");
The UMD build is also available on unpkg:
<script src="https://unpkg.com/@metronlabs/rx-form-data/lib/index.umd.js"></script>
You can find the library on window.RxFormData
.
Usage
import RxFormData from "@metronlabs/rx-form-data";
const { subscribe, register, dispatch, ACTION_TYPE } = RxFormData(
"some-form-id",
(formvalues, formvalidation, formdata) => {
console.log(
"ON SUBMIT HANDLER CALLED",
formvalues,
formvalidation,
formdata
);
return Promise.resolve([formvalues]);
}
);
dispatch(ACTION_TYPE.REGISTER_ALL);
dispatch(ATION_TYPE.REGISTER, ["some-field-x", "some-field-y"]);
const unregister = register(["some-field-x", "some-field-y"]);
dispatch(ACTION_TYPE.ADD_DECODERS, [
{
name: "validation-for-some-field-x",
use: [
(formvalues) => {
return true;
}
],
messages: ["Input is invalid"]
}
]);
const unsubscribe = subscribe((formvalues, formvalidation) => {
console.info("FORM DATA SUBSCRIBER", formvalues, formvalidation);
});
const unsubscribe2 = subscribe((formvalues, formvalidation) => {
console.info("FORM DATA SUBSCRIBER II", formvalues, formvalidation);
});
setTimeout(() => {
unsubscribe();
unsubscribe2();
}, 2 * 60 * 1000);
setTimeout(() => {
dispatch(ACTION_TYPE.DESTROY);
}, 3 * 60 * 1000);
Contribute
First off, thanks for taking the time to contribute!
Now, take a moment to be sure your contributions make sense to everyone else.
Reporting Issues
Found a problem? Want a new feature? First of all see if your issue or idea has already been reported.
If not, just open a new clear and descriptive issue.
Submitting pull requests
Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.
- Fork it!
- Clone your fork:
git clone https://github.com/<your-username>/@metronlabs/rx-form-data
- Navigate to the newly cloned directory:
cd @metronlabs/rx-form-data
- Create a new branch for the new feature:
git checkout -b features/my-new-feature
- Install the tools necessary for development:
npm install
- Make your changes.
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin features/my-new-feature
- Submit a pull request with full remarks documenting your changes.
License
MIT License © Ahmed Tadde
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice aTd this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.