Skip to content

int0h/hyper-value

Repository files navigation

Hyper-value

Build Status Coverage Status

This is a library designed to help application data management.

At this point it is recommended to use with hv-jsx and hv-dom. You can find an introduction tutorial here: https://medium.com/@int0h/hyper-value-living-data-in-your-application-a54aab68d8b1

Docs: https://int0h.github.io/hyper-value

Demos

hv-counter-app — simple counter application

hv-todo-list — todo-mvc like application

hv-async-app — async demo

Structure

This library consists of the core and heplers.

core - is a simple wrapper for any javascript value that allows to read / write the value inside. Also it provides a way to watch changes of this value and react to them.

helpers - are some utility functions designed to help with most common use cases. They may (and may not) take a hyper-value as an argument and they may (or may not) return new hyper-values. At this point all helpers are methods of specific HyperScope (it will be described below), but it will likely change in near future.

Core

To create a hyper-value you can use a HyperValue constructor:

import {HyperValue} from 'hyper-value';
const myHyperValue = new HyperValue(myValue);

hyper-value can be watched like this:

// hs - is hyper-scope
hs.watch(myHyperValue, (newValue, oldValue) => {
	console.log(`
		current value has just been set to: ${newValue};
		old value was: ${oldValue};
	`);
})

hyper-scope

Hyper-scope is a utility entity who owns hyper-value watchers, it can be created manually but it usually should be created for you by a library or framework.

API Specification

Class HyperValue:

Creating an instance:

const hv = new HyperValue(1);

The constructor takes only one argument which is the initial value of HyperValue to be created.

Each HyperValue has these fields:

  • $ property - is an interface to inner value. It's recommended way to read and write;
  • g method - allows to get the value inside. It's not fully stable (it's likely to be renamed to get), use $ when it's possible. It also takes an optional argument silent, which can be used to avoid recording its owner from adding to dependencies inside auto scope and similar ones;
  • s method - allows to set the value inside. It's not fully stable (it's likely to be renamed to set), use $ when it's possible. It takes only one argument which is the new value;

Helpers

Documentation about helpers can be found here:

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published