From 95c9e00d3a259a4ce9abc20cc458b016c506e684 Mon Sep 17 00:00:00 2001 From: Gianluca Date: Thu, 25 Feb 2021 11:01:51 +0000 Subject: [PATCH 1/8] fix: typo in variable name --- .../datastore/src/replication/fetch/FetchReplicator.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/datastore/datastore/src/replication/fetch/FetchReplicator.ts b/packages/datastore/datastore/src/replication/fetch/FetchReplicator.ts index 8ddc63794..335c8b2a5 100644 --- a/packages/datastore/datastore/src/replication/fetch/FetchReplicator.ts +++ b/packages/datastore/datastore/src/replication/fetch/FetchReplicator.ts @@ -46,7 +46,7 @@ export class FetchReplicator { if (config.liveupdates?.enabled) { logger("Initializing subscription replication"); const queries = buildGraphQLCRUDSubscriptions(model); - const subscrptionOptions = { + const subscriptionOptions = { config: config.liveupdates, client: client, networkIndicator: networkIndicator, @@ -54,7 +54,7 @@ export class FetchReplicator { queries: queries, model: model }; - this.subscriptionReplicator = new SubscriptionReplicator(subscrptionOptions); + this.subscriptionReplicator = new SubscriptionReplicator(subscriptionOptions); } // provide the model with a reference to the replicator model.setReplicator(this); @@ -71,9 +71,6 @@ export class FetchReplicator { if (this.deltaReplicator) { this.deltaReplicator.start(); } - if (this.subscriptionReplicator) { - this.subscriptionReplicator.start(); - } this.replicationFlag = true; } From 42d7c9056a67697914b6247102cc5308a704c39f Mon Sep 17 00:00:00 2001 From: Gianluca Date: Thu, 25 Feb 2021 11:02:51 +0000 Subject: [PATCH 2/8] chore: getter for replicator network status --- .../datastore/src/replication/GraphQLReplicator.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/datastore/datastore/src/replication/GraphQLReplicator.ts b/packages/datastore/datastore/src/replication/GraphQLReplicator.ts index ba68d94e9..332974215 100644 --- a/packages/datastore/datastore/src/replication/GraphQLReplicator.ts +++ b/packages/datastore/datastore/src/replication/GraphQLReplicator.ts @@ -105,4 +105,12 @@ export class GraphQLReplicator { this.mutationQueue?.stopReplication(); this.models.forEach(model => model.getReplicator()?.stopReplication()); } + + /** + * Getter method for replicator + * network status indicator + */ + public getNetworkIndicator() { + return this.networkIndicator; + } } From 24b1b2f9ce5fddf7241a9b6c2809f8516ed0876c Mon Sep 17 00:00:00 2001 From: Gianluca Date: Thu, 25 Feb 2021 11:03:14 +0000 Subject: [PATCH 3/8] chore: expose datastore network indicator --- packages/datastore/datastore/src/DataStore.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/datastore/datastore/src/DataStore.ts b/packages/datastore/datastore/src/DataStore.ts index 9e4181a30..5cbda94fd 100644 --- a/packages/datastore/datastore/src/DataStore.ts +++ b/packages/datastore/datastore/src/DataStore.ts @@ -7,6 +7,7 @@ import { DataStoreConfig } from "./DataStoreConfig"; import { createLogger, enableLogger } from "./utils/logger"; import { ModelReplicationConfig } from "./replication/api/ReplicationConfig"; import { mutationQueueModel, metadataModel } from "./replication/api/MetadataModels"; +import { NetworkStatus } from "./replication/network/NetworkStatus"; const logger = createLogger("DataStore"); // TODO disable logging before release @@ -95,4 +96,12 @@ export class DataStore { public stopReplication() { this.replicator?.stopReplication(); } + + /** + * Expose the Datastore network indicator to + * the client. + */ + public getNetworkIndicator() { + return this.replicator?.getNetworkIndicator(); + } } From 312b6d6bab775da4e36e49e3970ac6bcb337a07f Mon Sep 17 00:00:00 2001 From: Gianluca Date: Thu, 25 Feb 2021 11:03:24 +0000 Subject: [PATCH 4/8] chore: update sample app --- examples/react-datastore/src/App.tsx | 36 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/examples/react-datastore/src/App.tsx b/examples/react-datastore/src/App.tsx index c08d496c2..de5378d7b 100644 --- a/examples/react-datastore/src/App.tsx +++ b/examples/react-datastore/src/App.tsx @@ -5,6 +5,7 @@ import 'antd/dist/antd.css'; import { useFindTodos } from './datastore/hooks'; import { TodoList, AddTodo, Loading, Error, Header } from './components'; import { datastore } from './datastore/config'; +import { NetworkStatusEvent } from 'offix-datastore/types/replication/network/NetworkStatus'; function App() { @@ -12,23 +13,35 @@ function App() { const [addView, setAddView] = useState(false); const { loading, error, data, subscribeToUpdates } = useFindTodos(); + useEffect(() => { + datastore.getNetworkIndicator()?.subscribe({ + next: (event: NetworkStatusEvent) => { + if (event.isOnline) { + datastore.startReplication(); + setReplicating(true); + } else { + datastore.stopReplication(); + setReplicating(false); + } + } + }) + }) + useEffect(() => { // We can start replication on a per model basis // or for the entire store with: // datastore.startReplication // the `startReplication` method accepts an // optional filter - if (replicating) { - datastore.startReplication() - } - }, [replicating]); + datastore.startReplication() + }); - const toggleReplication = () => { - if (replicating) { - datastore.stopReplication() - } - setReplicating(!replicating) - } + // const toggleReplication = () => { + // if (replicating) { + // datastore.stopReplication() + // } + // setReplicating(!replicating) + // } useEffect(() => { const subscription = subscribeToUpdates(); @@ -59,12 +72,11 @@ function App() { From bc4572bbfde06005ed421dc5d81a5540af6ee4ed Mon Sep 17 00:00:00 2001 From: Gianluca Date: Thu, 25 Feb 2021 11:03:38 +0000 Subject: [PATCH 5/8] chore: bump version for release --- examples/react-datastore/package.json | 2 +- packages/datastore/datastore/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/react-datastore/package.json b/examples/react-datastore/package.json index ea92d08b6..440422563 100644 --- a/examples/react-datastore/package.json +++ b/examples/react-datastore/package.json @@ -16,7 +16,7 @@ "@types/react-dom": "^16.9.0", "antd": "~4.4.1", "graphql.macro": "^1.4.2", - "offix-datastore": "0.3.17", + "offix-datastore": "0.3.19", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.1", diff --git a/packages/datastore/datastore/package.json b/packages/datastore/datastore/package.json index b1effcd58..c31291d05 100644 --- a/packages/datastore/datastore/package.json +++ b/packages/datastore/datastore/package.json @@ -1,6 +1,6 @@ { "name": "offix-datastore", - "version": "0.3.18", + "version": "0.3.19", "main": "dist/index.js", "types": "types/index.d.ts", "repository": { From 4cbbf63e08ec5c030d345fb9ad66817a9b4a38a5 Mon Sep 17 00:00:00 2001 From: Gianluca Date: Thu, 25 Feb 2021 11:11:44 +0000 Subject: [PATCH 6/8] fix: lint issues --- packages/datastore/datastore/src/DataStore.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/datastore/datastore/src/DataStore.ts b/packages/datastore/datastore/src/DataStore.ts index 5cbda94fd..f288e7171 100644 --- a/packages/datastore/datastore/src/DataStore.ts +++ b/packages/datastore/datastore/src/DataStore.ts @@ -7,7 +7,6 @@ import { DataStoreConfig } from "./DataStoreConfig"; import { createLogger, enableLogger } from "./utils/logger"; import { ModelReplicationConfig } from "./replication/api/ReplicationConfig"; import { mutationQueueModel, metadataModel } from "./replication/api/MetadataModels"; -import { NetworkStatus } from "./replication/network/NetworkStatus"; const logger = createLogger("DataStore"); // TODO disable logging before release From d4cce9b697dca99eda5ef19bd933697cdffa8286 Mon Sep 17 00:00:00 2001 From: Gianluca Date: Thu, 25 Feb 2021 12:20:15 +0000 Subject: [PATCH 7/8] fix: remove uncommented code --- examples/react-datastore/src/App.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/examples/react-datastore/src/App.tsx b/examples/react-datastore/src/App.tsx index de5378d7b..1d231e21c 100644 --- a/examples/react-datastore/src/App.tsx +++ b/examples/react-datastore/src/App.tsx @@ -36,13 +36,6 @@ function App() { datastore.startReplication() }); - // const toggleReplication = () => { - // if (replicating) { - // datastore.stopReplication() - // } - // setReplicating(!replicating) - // } - useEffect(() => { const subscription = subscribeToUpdates(); return () => subscription.unsubscribe(); From 66f048c516d24973c875d9dc95c6c2aaeedf92c3 Mon Sep 17 00:00:00 2001 From: Gianluca Date: Thu, 25 Feb 2021 12:20:29 +0000 Subject: [PATCH 8/8] chore: bump datastore to 0.4.0 --- examples/react-datastore/package.json | 2 +- packages/datastore/datastore/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/react-datastore/package.json b/examples/react-datastore/package.json index 440422563..d96f1d266 100644 --- a/examples/react-datastore/package.json +++ b/examples/react-datastore/package.json @@ -16,7 +16,7 @@ "@types/react-dom": "^16.9.0", "antd": "~4.4.1", "graphql.macro": "^1.4.2", - "offix-datastore": "0.3.19", + "offix-datastore": "0.4.0", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.1", diff --git a/packages/datastore/datastore/package.json b/packages/datastore/datastore/package.json index c31291d05..83e019070 100644 --- a/packages/datastore/datastore/package.json +++ b/packages/datastore/datastore/package.json @@ -1,6 +1,6 @@ { "name": "offix-datastore", - "version": "0.3.19", + "version": "0.4.0", "main": "dist/index.js", "types": "types/index.d.ts", "repository": {