| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
11年前发布

数据访问和同步标准JS库:Orbit.js

Orbit.js 是一个标准库用于协调访问数据源,并保持它们的内容同步。Orbit提供了一个基础框架,用于在客户端应用程序构建高级功能比较:离线操作,维护和同步本地高速缓存,撤消/重做栈和特设的编辑环境。

目标:

  • Support any number of different data sources in an application and provide access to them through common interfaces.

  • Allow for the fulfillment of requests by different sources, including the ability to specify priority and fallback plans.

  • Allow records to simultaneously exist in different states across sources.

  • Coordinate transformations across sources. Handle merges automatically where possible but allow for complete custom control.

  • Allow for blocking and non-blocking transformations.

  • Allow for synchronous and asynchronous requests.

  • Support transactions and undo/redo by tracking inverses of operations.

  • Work with plain JavaScript objects.

 // Create data sources with a common schema    var schema = {      idField: '__id',      models: {        planet: {        }      }    };    var memorySource = new Orbit.MemorySource(schema);    var restSource = new Orbit.JSONAPISource(schema);    var localSource = new Orbit.LocalStorageSource(schema);      // Connect MemorySource -> LocalStorageSource (using the default blocking strategy)    var memToLocalConnector = new Orbit.TransformConnector(memorySource, localSource);      // Connect MemorySource <-> JSONAPISource (using the default blocking strategy)    var memToRestConnector = new Orbit.TransformConnector(memorySource, restSource);    var restToMemConnector = new Orbit.TransformConnector(restSource, memorySource);      // Add a record to the memory source    memorySource.add('planet', {name: 'Jupiter', classification: 'gas giant'}).then(      function(planet) {        console.log('Planet added - ', planet.name, '(id:', planet.id, ')');      }    );      // Log the transforms in all sources    memorySource.on('didTransform', function(operation, inverse) {      console.log('memorySource', operation);    });      localSource.on('didTransform', function(operation, inverse) {      console.log('localSource', operation);    });      restSource.on('didTransform', function(operation, inverse) {      console.log('restSource', operation);    });      // CONSOLE OUTPUT    //    // memorySource {op: 'add', path: 'planet/1', value: {__id: 1, name: 'Jupiter', classification: 'gas giant'}}    // localSource  {op: 'add', path: 'planet/1', value: {__id: 1, name: 'Jupiter', classification: 'gas giant'}}    // restSource   {op: 'add', path: 'planet/1', value: {__id: 1, id: 12345, name: 'Jupiter', classification: 'gas giant'}}    // memorySource {op: 'add', path: 'planet/1/id', value: 12345}    // localSource  {op: 'add', path: 'planet/1/id', value: 12345}    // Planet added - Jupiter (id: 12345)

项目主页:http://www.open-open.com/lib/view/home/1390181638586

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1390181638586.html
Orbit.js JavaScript开发工具包