JavaScript ORM 库 Neurosync

码农软件 · 软件分类 · ORM/持久层框架 · 2019-09-23 11:42:10

软件介绍

Neurosync 是一个 JavaScript ORM 库,支持离线和实时操作。没错,是 ORM,但并没有疯狂到直接连接到后台数据库。对 Neurosync 来说,数据库就是后端的 REST API,而 Neurosync 就是这个 API 的一个门面。

Neurosync 的生命周期非常简单:

  • 保存数据变更到本地存储

  • 发起 REST 请求

  • 如果请求成功则删除本地存储中的变更数据,标识为已保存,并发布到实时 API

  • 如果请求失败,因为应用本身是离线的,将等待应用在线并继续处理数据更改流程

  • 如果有待决的操作但是应用重启了,数据将会被恢复

一个简单的 TODO 应用示例代码:

var Todo = Neuro({
  name: 'todo',
  api: '/api/1.0/todo/',
  fields: ['name', 'finished_at'],
  timestamps: true,
  comparator: ['-finished_at', '-created_at'], // finished go to bottom, most recently created are at the top
  methods: {
    finish: function(finished) {
      this.$save('finished_at', finished ? Date.now() null);
    }
  },
  dynamic: {
    done: function() {
      return !this.finished_at;
    }
  }
});

var t0 = Todo.create({name: 'Download Neurosync'});
t0.$isSaved(); // true
t0.finish( true );
t0.done; // true
t0.$remove();

var t1 = new Todo({name: 'Use Neurosync'});
t1.$isSaved(); // false
t1.id; // UUID
t1.$save();

var t2 = Todo.boot({id: 34, name: 'Profit'}); // Todo data that already exists remotely
t2.$isSaved(); // true
t2.name = '???';
t2.$hasChanges(); // true

var t3 = Todo.fetch(45); // REST call if doesn't exist locally

Todo.all(); // [t1, t2, t3]

Todo.collect(t1, t2); // creates a collection of todos

var allRemote = Todo.fetchAll(function(all) {}); // call REST API

var f0 = Todo.find('name', 'Download Neurosync'); // first match
var f1 = Todo.find({done: true});

var w0 = Todo.where('done', true); // all done todos
var w1 = Todo.where({finished_at: null});

var g0 = Todo.get(34); // get cached version

var g1 = Todo.grab(34); // get cached version, otherwise call REST API
var a0 = Todo.grabAll(function(all) {}); // get all cached, if none cached call REST API

Todo.ready(function() {}); // when it has been initialized locally and/or remotely (depends on options).

Todo.refresh(); // re-fetch from REST API

var search0 = Todo.search({done: true}); // sends a search to the REST API (POST by default)

var searchPaged0 = Todo.searchPaged({done: true, page_offset: 0, page_size: 20});
searchPaged0.$next();

本文地址:https://www.codercto.com/soft/d/15219.html

iOS软件开发揭密

iOS软件开发揭密

虞斌 / 电子工业出版社 / 2011-5-1 / 79.00元

本书以严密的体系性提供了iPhone和iPad软件开发从入门到专家的系统性知识,并提供来源于真实项目的可重用商业代码。书中的每个实例都是项目经验的提炼,深入浅出地讲解iPhone和iPad软件开发的核心技术要点,基本涵盖了iOS软件开发在真实商业项目中所需要的所有主题,并将实例介绍的技术深度和超值的实用性结合在一起,成为本书的特色。 随书附赠的光盘中包含了书中大量案例的完整工程源代码,可以让......一起来看看 《iOS软件开发揭密》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具