前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >offline plugin的工作原理

offline plugin的工作原理

作者头像
Jerry Wang
发布2019-06-20 09:10:26
6590
发布2019-06-20 09:10:26
举报

Sent: Wednesday, 3 August, 2016 5:41 PM

The plugin is supported for use with applications on the Android and iOS platforms. The plugin provides the client with the ability to define offline stores for an OData producer. When an offline store is first opened, it synchronizes with the OData producer. OData requests made against this plugin use the available open offline stores.

Offline plugin是保证我们offline application能运行的最核心的组件了。帮助文档上说:The Offline OData plugin provides a OData httpclient based on datajs, a cross-browser JavaScript library. Thehttpclient resolves requests with the Offline OData plugin if the service root of the request matches one of the open stores. The httpclient defaults to using the original OData.defaultHttpClient if the requests service root does not match any of the currently open stores.

根据帮助文档描述:Offline app运行在设备上时,每次发起odata request时,首先会检查该request是否能够通过设备的local DB取值,如果能,直接从设备的local DB取。

我看了这个文档就有两个问题:

  1. “首先会检查该request是否能够通过设备的local DB取值”-在哪检查的?
  2. “如果能,直接从设备的local DB取”-怎么取?Javascript怎么能直接访问设备的local DB?

对于第一个问题:

我们project的config.xml里声明了这个offline plugin的引用:

clipboard1
clipboard1

进入这个plugin的folder,会看到一个配置文件:

clipboard2
clipboard2

里面指定了这个plugin可直接供UI5 框架调用的OData.js和OfflineStore.js,以及JS直接访问Android device DB的Java文件:

clipboard3
clipboard3

回到之前的问题,plugin咋知道哪些url可以从local DB取,哪些url需要发到后台?

代码写得很清楚:在OData.js里,我们应用define的url会存在openStores里。在Js的request方法里,会逐一比较当前request url是否在offline store里定义过,

clipboard4
clipboard4

如果是,handle = true.

就进这个分支,通过odata.request call设备原生API访问local DB

clipboard5
clipboard5

否则call 默认的httprequest把请求发给后台:

clipboard6
clipboard6

那么js 又是如何call原生的Java API?通过exec。

clipboard7
clipboard7

在Android folder下有exec的实现代码:

clipboard8
clipboard8

这里写了,技术上来说:两种方式实现js call Java:

clipboard9
clipboard9
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年06月19日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Sent: Wednesday, 3 August, 2016 5:41 PM
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档