Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Introduction

Stephen Oney edited this page Jan 6, 2014 · 9 revisions

ConstraintJS is a JavaScript library for creating constraints — relationships between variables that are declared once and automatically maintained. An example of a simple constraint is: y is always x + 1. Setting var y = x + 1 in standard JavaScript won't work because as soon as x changes, y would be invalid:

var x = 2,
    y = x + 1;
// ...
x = 20; // y is no longer === x + 1

With ConstraintJS, this relationship would be expressed by declaring x as a constraint variable and declaring var y = x.add(1):

var x = cjs(2),
    y = x.add(1); // y <- x+1
// ...
x.set(20); // y.get() === 21

Now, whenever x changes, y's value automatically updates with it. ConstraintJS allows constraints to be declared between variables, DOM attributes, CSS properties, and more.


Next: Using ConstraintJS

Clone this wiki locally