@diory/client-js 0.2.0-rc17 → 0.2.0-rc19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export declare function debounce(func: any, wait: number, immediate?: boolean): () => typeof func;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.debounce = void 0;
4
+ function debounce(func, wait, immediate = false) {
5
+ let timeout;
6
+ // eslint-disable-next-line func-names
7
+ return () => {
8
+ // @ts-ignore
9
+ const context = this;
10
+ const args = arguments;
11
+ // eslint-disable-next-line func-names
12
+ const later = function () {
13
+ timeout = null;
14
+ if (!immediate)
15
+ func.apply(context, args);
16
+ };
17
+ const callNow = immediate && !timeout;
18
+ clearTimeout(timeout);
19
+ timeout = setTimeout(later, wait);
20
+ if (callNow)
21
+ func.apply(context, args);
22
+ };
23
+ }
24
+ exports.debounce = debounce;
@@ -6,6 +6,7 @@ const diograph_1 = require("@diograph/diograph");
6
6
  const getConnectionClients_1 = require("../utils/getConnectionClients");
7
7
  const getDefaultDiosphere_1 = require("./getDefaultDiosphere");
8
8
  const getDefaultDiograph_1 = require("./getDefaultDiograph");
9
+ const debounce_1 = require("../connectionClient/utils/debounce");
9
10
  class DioryClient {
10
11
  constructor(dataClients) {
11
12
  this.dataClients = [];
@@ -121,8 +122,8 @@ class DioryClient {
121
122
  this.dataClients = dataClients;
122
123
  this.diosphere = new diosphere_js_1.Diosphere();
123
124
  this.diograph = new diograph_1.Diograph();
124
- this.diosphere.saveDiosphere = this.saveDiosphere;
125
- this.diograph.saveDiograph = this.saveDiograph;
125
+ this.diosphere.saveDiosphere = (0, debounce_1.debounce)(this.saveDiosphere, 1000);
126
+ this.diograph.saveDiograph = (0, debounce_1.debounce)(this.saveDiograph, 1000);
126
127
  }
127
128
  }
128
129
  exports.DioryClient = DioryClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.2.0-rc17",
3
+ "version": "0.2.0-rc19",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "Olli-Pekka Pohjola <op@diory.me>, Jouni Alanen <jouni@diory.me>",
@@ -0,0 +1,18 @@
1
+ export function debounce(func: any, wait: number, immediate = false) {
2
+ let timeout: any
3
+ // eslint-disable-next-line func-names
4
+ return (): typeof func => {
5
+ // @ts-ignore
6
+ const context = this
7
+ const args = arguments
8
+ // eslint-disable-next-line func-names
9
+ const later = function () {
10
+ timeout = null
11
+ if (!immediate) func.apply(context, args)
12
+ }
13
+ const callNow = immediate && !timeout
14
+ clearTimeout(timeout)
15
+ timeout = setTimeout(later, wait)
16
+ if (callNow) func.apply(context, args)
17
+ }
18
+ }
@@ -13,6 +13,7 @@ import { getConnectionClients } from '../utils/getConnectionClients'
13
13
 
14
14
  import { getDefaultDiosphere } from './getDefaultDiosphere'
15
15
  import { getDefaultDiograph } from './getDefaultDiograph'
16
+ import { debounce } from '../connectionClient/utils/debounce'
16
17
 
17
18
  class DioryClient implements IDioryClient {
18
19
  dataClients: IDataClient[] = []
@@ -28,8 +29,8 @@ class DioryClient implements IDioryClient {
28
29
  this.diosphere = new Diosphere()
29
30
  this.diograph = new Diograph()
30
31
 
31
- this.diosphere.saveDiosphere = this.saveDiosphere
32
- this.diograph.saveDiograph = this.saveDiograph
32
+ this.diosphere.saveDiosphere = debounce(this.saveDiosphere, 1000)
33
+ this.diograph.saveDiograph = debounce(this.saveDiograph, 1000)
33
34
  }
34
35
 
35
36
  selectRoom = (roomObject: IRoomObject): IRoom => {