- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有两个关于 Firebase web platform 的相关问题的 synchronisation of locally-modified data to the server :
Every client sharing a Firebase database maintains its own internal version of any active data. When data is updated or saved, it is written to this local version of the database. The Firebase client then synchronizes that data with the Firebase servers and with other clients on a 'best-effort' basis.
数据修改方法( set()
, remove()
, ETC)可以接受一个 onComplete
回调参数:
A callback function that will be called when synchronization to the Firebase servers has completed. The callback will be passed an
Error
object on failure; elsenull
.var onComplete = function(error) {
if (error) {
console.log('Synchronization failed');
} else {
console.log('Synchronization succeeded');
}
};
fredRef.remove(onComplete);
在上面的示例中,fredRef.remove()
回调应该接收什么样的错误?
有没有办法区分暂时性错误和永久性错误?
我们应该如何处理这些错误/从这些错误中恢复?
对于临时错误,我们是否需要在短时间后再次调用 fredRef.remove()
以重试操作?
我意识到每次调用 set()
和 remove()
都会收到一个单独的同步成功/失败消息导致 onComplete
回调。但我正在寻找一种方法来确定整个 Firebase 客户端的全局同步状态。
我想使用 beforeunload
事件监听器在所有修改的数据同步到服务器之前,当用户试图离开页面时警告用户,我正在寻找类似 firebase.isAllModifiedDataSynced()
的函数。像这样:
window.addEventListener('beforeunload', function (event) {
if (!firebase.isAllModifiedDataSynced()) {
event.returnValue = 'Some changes have not yet been saved. If you ' +
'leave this page, your changes will be lost.';
}
});
以下是 Google 云端硬盘中相同功能的示例:
我知道 special /.info/connected
location :
it is useful for a client to know when it is online or offline. Firebase clients provide a special location at
/.info/connected
which is updated every time the client's connection state changes. Here is an example:var connectedRef = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/.info/connected");
connectedRef.on("value", function(snap) {
if (snap.val() === true) {
alert("connected");
} else {
alert("not connected");
}
});
特殊的 /.info/connected
位置可以像这样连接到 beforeunload
事件监听器:
var connectedRef = new Firebase('https://myapp.firebaseio.com/.info/connected');
var isConnected = true;
connectedRef.on('value', function (snap) {
isConnected = snap.val();
});
window.addEventListener('beforeunload', function (event) {
if (!isConnected) {
event.returnValue = 'Some changes have not yet been saved. If you ' +
'leave this page, your changes will be lost.';
}
});
我的问题是:
isConnected
为true
,这是否也意味着所有修改的数据都已同步到服务器?如果不是,应用程序如何确定整个 Firebase 客户端的全局同步状态?
/.info/synchronized
位置?onComplete
回调的同步成功/失败结果?最佳答案
In the example above, what kind of errors should the fredRef.remove() callback expect to receive?
Client is offline (network connection lost) ?
不,这不会导致将错误传递给完成监听器。它只会导致(尚未)调用完成监听器。
Firebase server is temporarily overloaded or down for maintenance, but will be available again soon?
没有。这与没有网络连接本质上是一样的。
Permission denied (due to security rules) ?
是的,这确实会导致将错误传递给完成处理程序。
Database location does not exist?
不,这不会导致完成监听器发生错误。
If isConnected is true, does this also mean that all modified data has been synced to the server? i.e. Does "connected" also mean "synced"?
不,它没有。 .info/connected
将在与数据库建立连接时以 true 触发。
If not, how can the app determine the global sync status of the whole Firebase client?
目前无法确定您的本地数据是否与服务器保持同步。
Is there a special /.info/synchronized location?
不,这样的位置不存在。
Does the app need to manually keep track of the sync success/failure result of every onComplete callback?
这取决于用例。但是,如果您只想知道何时执行所有写入,请推送一个虚拟值并等待其完成。由于 Firebase 按顺序执行写入,您可以确定在那个阶段您已经获得了其他事件。
关于javascript - 本地修改数据的 Firebase 同步 : handling errors & global status,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35280502/
我对文档有点困惑。请纠正我。 git 状态- 显示当前本地工作目录状态 git status -u- 显示未跟踪的文件(也是本地的) git 状态 -uno- 不显示未跟踪的文件(也是本地的)?? 后
我有一个具有 12 个虚拟机资源的 ARM 模板。每个虚拟机都有 1 个与其关联的 CustomLinuxScript 扩展资源。 某些 CustomLinuxScript 扩展失败并出现错误:状态文
我有一个具有 12 个虚拟机资源的 ARM 模板。每个虚拟机都有 1 个与其关联的 CustomLinuxScript 扩展资源。 某些 CustomLinuxScript 扩展失败并出现错误:状态文
我有以下 JavaScript 代码: alert(data.status); data 是一个 JSON 对象,其字段之一是 status ( bool 字段)。 当JSON.stringify(d
我在验证表单时遇到此错误,如何解决它。 代码: app.post('/',[ check('username','Error occured in Username').trim().isEmai
我正在开发一个使用 fork() exec() wait() 的 C 程序。第一个进程有以下代码: int main(int argc, const char * argv[]) { // inser
我想在 git status 上运行 linter,但是似乎没有 pre-status 和 post-status Hook 。 如何给 git 添加一个钩子(Hook)? fine docs对此事保
我需要获取所有 current_user.friends 状态,然后按 created_at 对它们进行排序。 class User a.created_at } end current_user.
我在 Eloquent 中使用 orWhere 时遇到问题。 我有一个团队,这个团队有一些资料。我想获取状态 = 1 或状态 = 2 的所有配置文件。但我无法让它工作。 我的代码是这样的: $prof
http://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic.html#INISCRPTACT 根据这
我们在 IIS 6.0 上托管 WCF 服务的服务器之一上观察到以下行为: IIS 日志显示所用时间的值较高 (> 100000) HTTP 状态码是 200 sc-win32-status 代码显示
在 Dynamics CRM 中,潜在客户实体同时具有状态和状态原因。使用 API 我可以获得所有状态原因。我被绊倒的地方是当我的用户选择状态原因时我想倒退并找出哪个状态与所选状态原因相关联。 以下是
我很好奇返回响应和仅创建响应的区别。 我见过大量使用 return res.status(xxx).json(x) 的代码示例和res.status(xxx).json(x) . 谁能详细解释一下两者
文档并没有真正说明 status 是什么。 status 到底是什么? http://man7.org/linux/man-pages/man2/exit_group.2.html 最佳答案 来自ex
An earlier question导致了一些关于如何检查 Git 存储库是否包含脏索引或未跟踪文件的想法。我从那次讨论中采纳的答案如下: #!/bin/sh exit $(git status -
ECSHOP出现 XMlHttpRequest status:[500] Unknow status 这个错误 把/admin/templates/top.htm 这个文件中{insert_scr
我有以下代码用于通过 Twitter4J 获取推文: List statuses; Paging paging = new Paging(1, LIMIT); statuses = twitter.g
非常不言自明。我正在制作一个脚本并且遇到了被使用和解析的情况,但它们的输出似乎总是完全相同。 最佳答案 git status --branch --porcelain "显示分支的状态(ahead,
我有一张表,上面有如下记录 表A subid clickid status datetime 1 123 low 2018-07-24 20:20:44 2 123
如果确实缺少资源,我的 API 将返回以下内容 { "code": 404, "message": "HTTP 404 Not Found" } 当我使用代码 Response.sta
我是一名优秀的程序员,十分优秀!