-
Notifications
You must be signed in to change notification settings - Fork 117
React native compatibilize #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Parse 是如何实现的? |
Parse 的 File 不依赖 currentUser,logOut() 是异步的,分了 currentUser() 与 currentUserAsync()。 |
现在 AV.User 相关的部分,已经改成返回 promise 的 async 形式了吗?我觉得这个还是需要慎重,毕竟会影响现在所有用户的代码。 我觉得我们可以尝试增加异步 API,然后在文档中建议大家统一使用异步 API。 |
@leeyeh 这版的更改是把原有的 和Parse的API保持一致,不光使用户的迁移成本降低,而且,对于一些已有的针对Parse的插件,可以比较方便的移植一下配合LeanCloud JS SDK使用。 Parse的1.5.0版本SDK里面,加入了
Parse JS SDK的1.6.0版本进行了大规模重构,正式添加 SDK中用到 针对这几个影响到的地方,我建议:
这样的话,代码的改动不至于太大。对于browser和node环境的用户来说,没有任何API的改变;对于React Native的用户来说,应该期望他们使用 我有一个branch参考Parse的1.5.0版本做了修改。用了一两周下来还没发现什么明显的问题。如果有需要的话,我可以去整理一下发个PR。 |
478be0e
to
33ab72c
Compare
这个分支是最终版本了么? @leeyeh |
是的,请再看一下。 |
一个已知的问题,JavaScriptCore 不支持 atob,所以现在通过 base64 构造 File 会报错。需要调查一下有没有替代的 API。 |
var _ = require('underscore'); | ||
var Promise = require('../promise'); | ||
|
||
var Storage = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storage 后续会设置上什么量,最好能够在此有个提前定义。
比如
var Storage = {
// async 用来判断本地存储是同步接口还是异步接口。
// 默认为 false,当在 React Native 中使用时会变为 true,异步接口。
async: false
};
现在原来接口是否兼容? |
原来的接口没有变化,但我不能确定是否引入问题因为现在的测试是跑不通的 😭 ,增加了 currentAsync 接口,我补下测试。 |
我记得原来是十四个单元测试跑不同。可以尝试下切到 master 分之跑一下。 |
@@ -78,7 +78,15 @@ _.extend(Promise, /** @lends AV.Promise */ { | |||
*/ | |||
as: function() { | |||
var promise = new Promise(); | |||
promise.resolve.apply(promise, arguments); | |||
if (arguments[0] && typeof arguments[0].then === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
推荐统一使用 underscore 来处理类型判断。
我们是不是可以先发个 RC1 @killme2008 |
@leeyeh 可以的,我是想测试下在云引擎下的兼容性,这是 js sdk 最大的用户。 |
# Conflicts: # lib/browserify-wrapper/localstorage-browser.js
744eda3
to
c1d54b3
Compare
Fix #158. |
👍 |
e1c92d9
to
3d4ab34
Compare
看了下,没有问题。 |
see #134.
修复了
xmlhttprequest
模块未找到的问题。兼容
AsyncStorage
。现在有一个问题:
由于 React Native 的
AsyncStorage
是异步的,所以所有直接或间接地调用了localStorage
模块的 API 都是异步的了,其中原来是同步的、对用户 public 的 API 有:new AV.File();
// 需要关联当前用户为 ownerAV.User.current()
AV.User.logOut()
一种方案是,保留原有的同步 API,给所有的 API 增加一个同名的异步 API,比如
AV.User.currentAsync()
。这个方案的问题是用户以及大量内部 API 需要关心当前的运行环境来选择调用哪个 API。第二种方案是把原有的 API 变为异步(同步也可以包装成异步)。这个的问题是不向前兼容。
还有不管怎样都有的问题是,异步的
new AV.File();
好别扭。Fix #158.