From 2ec3d5ef1df03ba87d92d397d618f24937c95d87 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Mon, 4 May 2020 17:23:16 +0500 Subject: [PATCH] api: add auto syncing after 3 minutes --- packages/core/api/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/core/api/index.js b/packages/core/api/index.js index 7045059f7..1da222629 100644 --- a/packages/core/api/index.js +++ b/packages/core/api/index.js @@ -14,6 +14,7 @@ import EventManager from "../utils/event-manager"; class Database { constructor(context) { this.context = new Storage(context); + this._syncInterval = 0; } async init() { @@ -39,6 +40,11 @@ class Database { this.delta = await Content.new(this, "delta", false); /** @type {Content} */ this.text = await Content.new(this, "text", false); + + if (this._syncInterval) clearInterval(this._syncInterval); + this._syncInterval = setInterval(async () => { + this.ev.publish("sync"); + }, 60 * 1000 * 3); } sync() {