Hydraulik
Hydraulik is an experimental react library for writing state handling components.
Usage
There is a separate documentation for the cli and types available.
import React Component from 'react'import Schema type skip Klass from 'hydraulik'import Str from 'hydraulik-types' @ extend Schema var klass = klass klass var users = klasssetsusers user = klasssetsuser usersusers // these components automatically listen for changed datavar UserList = users
Motivation
After writing several apis and single page apps I've got frustrated with repeating myself over and over again. I want to define how my data behaves declaritive. With as little mental overhead as possible.
Installation
Requirements: nvm
mkdir $projectNamecd $_npm initnpm install hydraulik-cli --save-dev/hydraulik initnpm install # or in one line mkdir $projectName && cd $_ && npm init && npm install hydraulik-cli --save-dev && /hydraulik init && npm install
Test
Hydraulik uses jest for testing. You can run its test by
$ npm test
.
If it dosn't work try running $ nvm use
in the hydraulik dir and reinstall the dependencies.
API
Schema - Set
@type(type: Type, [name = typeName], [preset = null])
Takes a Type that implement this interface. The name of the type is the Types name downcased. You can overwrite the type behavior on an child class. preset == default value. Only if value null or undefiend.
@skip([val: Int])
@skip() skips as many matches as provided in props.skip. defaults to 0 if params.skip isn't defined @skip(int) skips as many as are defined for int
if skip is 0 nothing is skiped
@limit([val: Int])
@limit() limits as many matches as provided in props.limit. defaults to 0 if params.limit isn't defined @limit(int) limits as many as are defined for int
if limit is 0 nothing is limited if limit is 1 it returns the element without the surrounding array
#filter(filterFn: function(val))
filters the set. FilterFn has to return a boolean. Val is an element of the set. You can access args from outside via val.params. Params from the component
ObserverSet/ObserverSubset
instances of the ObserverSet/ObserverSubset are stored in the Klass instance variable sets.
create(argObj: Object)
update(argObj: Object, query: Object)
destroy(query: Object)
Component(ComposedComponent: Component)
ComponentError(ComposedComponent: Component)
Contributing
Code of Conduct
Issues & Feature Requests
If you encounter a bug, inconsistencies or if anything isn't clear or clear enough open an issue. If you want a feature. Open an issue and we will discuss it. I'm happy to introduce you to hydraulik's code base. Feel free to reopen issues and claim unassigned issues for yourself to solve. The issue doesn't have to be code relatet. If you think that there can be something done with this projects organization open an issue.
Guide
The source code lives in the src folder.
hydraulik.jsx
exports all classes that can be accessible through import * from 'hydraulik'
klass.jsx
The Class contains all sets. Builds sets if #sets is called the first time. Build with the klassBuilder.
klassBuilder.jsx
It makes that the BaseSet and SubSet share the same storage. Converts sets into observed sets
observerSet.jsx
inherits from observerSubset and registers new action to the dispatcher
observerSubset.jsx
The adapter for the different set types. The user interacts with its methods.
schema.jsx
The DSL for Hydraulik.
schema-decorators.jsx
decorators for the schema.
*-set.jsx
TODO - move to own module sets provide crud operations and validation for an data table
setEvents.jsx
The events an observer set listens to.
Roadmap
- add a server/websocket set
- add relations and co-dependent constrains.
- remove the need to register a schema manually.