- 授权协议: MIT
- 开发语言: JavaScript
- 操作系统: 跨平台
- 软件首页: https://github.com/ClickerMonkey/neurosync
- 软件文档: https://github.com/ClickerMonkey/neurosync
软件介绍
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();
Dojo权威指南
拉塞尔 / 李松峰、李丽 / 机械工业出版社 / 2009-4 / 79.00元
通过使用Dojo这个工业强度的JavaScript工具箱,我们可以比使用其他任何Ajax框架更高效、更容易地创建JavaScript或Ajax驱动的应用程序和站点。 《Dojo权威指南》向读者展示了如何充分利用Dojo工具箱中包含的大量实用特性,以前所未有的效率开发出功能丰富、响应敏捷的Web应用程序。读者通过《Dojo权威指南》能够学习到创建复杂布局和表单控件(常见于高级桌面应用程序)的技......一起来看看 《Dojo权威指南》 这本书的介绍吧!
