Vibe.js
Install
yarn add vibejs
npm install vibejs
Tests
yarn test
For now vibejs has 34 tests.
Documentation
Core
There are 3 core concepts:
- Model and EntitySubject
- EntityStore
- Directory and DirectorySubject
Model
Model is description of entity.
You can describe it like this:
const User = 'User' structure: name: typesAttribute mother: types // reference to entity with name 'User' mother: types //same wrappedValues: // you can create wrapped structures age: typesAttribute computed: { return thisname } mutations: { thisname = newName; } ;
After this, you can insert new entity and observe it.
User;const subject = User;
What happens:
- You push json into model's
insertEntity
method - Model checks its structure and sets default if not set
- Model pushes entity into store
- Store notifies everybody, who is observing entity of type
User
andid=1
.
And now we got subject. In vibejs subject is object to work with entity.
At this point you already can use subject
to access and change reactive entity's data. For example
User;const reactiveInterface = subjectinterface;reactiveInterfacefather = 5; // access relation directly by ireactiveInterfacefather = Userinterface // or by subject's interfacereactiveInterfacefathername = "Somebody else"// after this line User#5 will have name equals `Somebody else` and user#1 will get updated
But we want to compose different data, like models or just primitives. For example, if you need screen, where user supposed to change his name.
We need to compose newUserName
and entity he updates.
To do this, we need to define Directory
const UpdateProfileDirectory = 'UpdateProfile' structure: newUserName: typesAttribute profile: types mutations: { /* fetch(...).then(response => { User.observe(this.profile.id) .mutate(response, 'Updated from updateProfile') })*/ // we can commit our mutations with text message for debugging purposes. } Store
Directory has no identifier. It is just structure of document you need.
So, at some point it's nice already. But what about changes? Reacting only for necessary data changes is core point of Vibe. It means, any subject won't get updated if its attribute is not updated or its relation is not updated.
Here are examples how you subscribe to changes of entity
subjectobservable
... or to directory
UpdateProfileDirectoryobservable;
It means, you won't need to react to all changes, like in Flux
solutions.
You create structure for a concrete task. You define relationships and your durectory will only get updated if this relationships are updated(and they will update if their relationships are updated and like this...).
TODO:
- JSONifying subjects
- Persistence of store and directories
- Examples with vue, react.