https://github.com/extremeprog-com/statetree
Library for creation data-oriented architecture of web applications.
https://github.com/extremeprog-com/statetree
async async-data
Last synced: 4 months ago
JSON representation
Library for creation data-oriented architecture of web applications.
- Host: GitHub
- URL: https://github.com/extremeprog-com/statetree
- Owner: extremeprog-com
- License: mit
- Created: 2016-08-25T00:16:02.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2025-08-26T01:40:10.000Z (10 months ago)
- Last Synced: 2026-01-23T16:48:46.297Z (5 months ago)
- Topics: async, async-data
- Language: JavaScript
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# statetree
Data-oriented architecture for web applications.
## Installation
```bash
$ npm install --save-dev statetree
```
## AsyncData
AsyncData is a wrapper for objects that are often updated, changed and synced.
### Initialization
```javascript
var User = new AsyncData();
```
### Properties
```javascript
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.
```javascript
User.getPromise().then(function() {
console.log(User.Name + 'has been updated');
})
```
**_update**
***
Calls resolve when data is received from the server, merges data.
```javascript
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.
```javascript
if(User.isChanged()) console.log(User.Name + 'changed');
```
**getChangedFields**
***
Returns fields that have been changed locally.
```javascript
User.setUpdating(function(apply, error, reject) {
$http
.post('/api/users', User.getChangedFields())
.success(function() {
apply();
})
.error(function() {
reject();
error();
})
})
```
**revert**
***
Revert old value
```javascript
User.setUpdating(function(apply, error, reject) {
$http
.post('/api/users', User)
.success(function() {
apply();
})
.error(function() {
reject();
User.revert();
})
})
```