Cekoya
Purposes
I wroked hard on building another library called modelizejs. These two share the same targets except that Cekoya should plugginable. I worked on projet when I wanted to use modelizejs but didn't want some feature that I thought were overwhelming for my use case. With Cekoya, I do a second attempt of building something everyone would enjoy. A Model library that is DRY.
Note The whole package was building under ES6 JavaScript standards. I recommend using them when working on new JavaScript. This said, the package comes with firenpm which has a basic webpack config to build the package if you want to deploy it at home.
Installation
npm install --save cekoya// oryarn add cekoya
Usage
Usage by proxy
Something I wanted to achieve long time ago with modelizejs was overriding default getter on class. I discovered Proxies.
const user = Cekoya; console // Outputs "John";console // Outputs "John";
If you instanciate a new Cekoya object, Proxies won't be applied to the object. Calling user.firstName
will then return undefined
. And that's bad.
Extension
This package should be used by extension. You create models that extends this one. You could create getters and setters just as any model.
Getters
Let's say I want to display my firstName attribute in upper case because I like the yelling style of the upper case.
{ return this; } const user = User; console // Outputs "JOHN";console // Outputs "JOHN";console // Outputs "John";
Setters
Let's say I want to set my age to at least 18 and pretend I'm an adult (Which I am, in real life).
const MINIMUM_AGE = 18; { return value >= MINIMUM_AGE ? value : MINIMUM_AGE; } const user = User; console // Outputs "18";
Plugins
To add a plugins to the package, simply override the static method plugins
on your class to return an array of Plugin classes.
Note Plugin classes must have a static method attach
which will receive the instance in parameters
static { modelconstructorprototype model_attributes; }
Main purpose of this is adding plugins like :
- Resource package for calling REST api
- Relationnal casting between models
- Casting of properties to other things
- ...
This is a new projet so this is a only a starts but I think it go far away.