技术开发 频道

择一个离线应用程序结构

Google Gears API Developer's Guide (Beta)

【翻译】:谷歌Gears应用程序接口开发者指南(Beta)

Choosing an Offline Application Architecture

【翻译】: 择一个离线应用程序结构
 【IT168 技术文档】

During development of Gears, we experimented with many different architectures for offline-enabled web applications. In this document we briefly look at some of them and explore their advantages and disadvantages.
 
【翻译】: 随着Gears的发展,我们为支持离线的WEB应用程序试验着不同的结构。在这篇文档中我们简要地探究一下一些关于它们的优势劣势。
 
As we experimented, we found some common themes. All the offline-enabled applications we created had the following design issues that needed to be addressed:
  • isolating the data layer
  • deciding which features to implement offline (connection strategy)
  • deciding on the app's modality
  • implementing data synchronization
【翻译】: 就像我们试验的一样,我们发现了一些公共的主题。所有我们制造的可以离线的应用程序有以下一些设计问题需要我们加以注意:
  • 分离的数据层
  • 决定是什么特征实现离线(连接策略)
  • 对应用程序的形式做出决定
  • 实现数据同步

Isolating the Data Layer
【翻译】: 分离的数据层
 
In most web applications today there is no real data layer.
【翻译】: 在今天大多数的WEB应用程序中并没有真正的数据层

 


Figure: No data layer

 

AJAX calls originate throughout the code, without any single clean communication layer. This is usually fine for AJAX applications because there is only one data source: the server. In effect, the API that the server exposes to AJAX acts as a data layer.
【翻译】: AJAX直接调用代码,而没有任何公共的层。这通常对AJAX应用程序是非常好的,因为只有一个层:服务器。事实上,服务器的API被AJAX当作一个数据层。

Architecture with a data layer

【翻译】: 数据层结构

In general, isolating the data layer is a good first step.

【翻译】: 通常,分离的数据层是好的第一步。

When you add a local datastore to your application, you will have a single place through which all data storage and retrieval requests pass.
【翻译】: 当你为你的应用程序增加一个本地数据存储时,你将有一个单独的位置用来处理你所有的数据存储以及取回经过的请求。

 

 
Figure: Data Layer

 

For example, if your AJAX application issues a JSON request directly to the server to get all the accounts for a user, you might change this to instead ask an intermediate object for all the accounts for the user. This object could then decide whether to retrieve the data from the server, the local store, or some combination of both. Similarly, when the application wants to update the user's accounts, the app does so by calling the intermediate object. The intermediate object can then decide whether to write the data locally, whether to send the data to the server, and it can schedule synchronization.
【翻译】: 例如,如果你的AJAX应用程序传出一个JSON给服务器获取一个用户的所有帐务,你可能改为请求一个中间对象来取代从服务器读取这个用户的所有帐务。这个对象来决定从服务器,本地存储,还是二者结合的方式重新找回数据。同样的,当应用程序想要更新用户帐户信息的时候,这个应用程序也是去调用这个中间对象。这个中间对象可以决定是否在本地写数据,还是将它们发送到服务器上,这些通过中间对象来决定。
You can think of this intermediate object as a data switch layer that implements the same interface as the data layer. As a first step, you can make the data switch forward all your calls to the data layer that interacts with the server. This step is useful since it is the code path that is followed when Google Gears is not installed or if the user doesn't want to enable the application to work offline. Note that a data switch is not strictly necessary (for example GearPad does not have a data switch layer).
【翻译】: 你可以将这个中间对象考虑成一个数据开关层,它负责实现和数据层相同的接口。第一步,你可以让使你所有的数据开关调用所有你的数据层以与你的服务器相结合。如果Google Gears没有被安装或者用户不想让应用程序离线工作,则这个步骤是非常有用的。注意这个数据开关并不是确实必要的(例如GearPad就没有数据开关层)

 


Figure: Data Switch Layer

 

The next step, as shown in the figure below, is to create a new local data layer that uses a Google Gears database instead of going to the web server for data. It's simpler if this data layer has the same interface as the existing data layer used to communicate with the server. If the interface is different then some translation needs to be done and you might as well do that inside this data layer.
【翻译】: 下一步,也是关键的一步,就是创建一个本地的数据层来使用Google Gears数据库代替访问WEB服务器上的数据。如果这个数据层拥有和已经存在的数据层相同的接口则与服务器通信将变得容易。如果这些接口不同,你则需要在这个数据层内做一些数据翻译的工作。
0
相关文章