New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

statetree

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

statetree

Library for creation data-oriented architecture of web applications.

latest
Source
npmnpm
Version
0.0.8
Version published
Maintainers
2
Created
Source

statetree

Data-oriented architecture for web applications.

Installation

$ npm install --save-dev statetree

AsyncData

AsyncData is a wrapper for objects that are often updated, changed and synced.

Initialization

var User = new AsyncData();

Properties

User._loaded        // identification that the object is loaded or not
User._updating      // identification that the object is updating or not
User._changed       // identification that the object has been changed locally (and is not saved)
User._old_value     // contains old version of the object
User._error         //
User._error_message //

Methods

getPromise

Returns a Promise object which you can use to know if the data has been loaded/updated.

User.getPromise().then(function() {
    console.log(User.Name + 'has been updated');
})

_update

Calls resolve when data is received from the server, merges data.

User.setUpdating(function(apply, error, reject) {
    $http
        .post('/api/users', User)
        .success(function() {
            apply();
        })
        .error(function() {
            reject();
            error();
        })
})

isChanged

Checks if the object has been changed locally.

if(User.isChanged()) console.log(User.Name + 'changed');

getChangedFields

Returns fields that have been changed locally.

User.setUpdating(function(apply, error, reject) {
    $http
        .post('/api/users', User.getChangedFields())
        .success(function() {
            apply();
        })
        .error(function() {
            reject();
            error();
        })
})

revert

Revert old value

User.setUpdating(function(apply, error, reject) {
    $http
        .post('/api/users', User)
        .success(function() {
            apply();
        })
        .error(function() {
            reject();
            User.revert();
        })
})

Keywords

state

FAQs

Package last updated on 26 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts