Crates

Crates is a resource that is available in the Allotize ecosystem. A crate aims to act like a box of information and you as a developer is able to define what data it includes, what is shared and what happens when it changes.

Let's take a quick look at a very simple example of a Crate. If we want to create a Counter that is available and editable by everyone on our website, we can simply define the user at the route counters/<counter> and define the desired data scheme.

const Counter = (counter) => Allotize.Crate({
    route: "counters/" + counter,

    state: {
      count: 0,
    },

    onChange: (oldState, newState) => {
      console.log(newState.count);
    }
});


const counter = Counter("counter-1");
counter.state.count += 1;