Skip to content

Commit

Permalink
Fix/snippets manual (#264)
Browse files Browse the repository at this point in the history
* Update snippets manually removing leading whitespace

* Fix issue where deeplinks would sometimes redirect to 404
  • Loading branch information
okdistribute authored Jul 20, 2022
1 parent 2ae842e commit ae5ddf7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions snippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
"update": "DITDocumentID *docID = [[ditto.store collection:@\"people\"] upsert:@{\n @\"name\": @\"Frank\",\n @\"age\": [NSNumber numberWithInt:31],\n @\"ownedCars\": [NSNumber numberWithInt:0],\n @\"friends\": @[]\n} error:nil];\n\n\nDITCollection *collection = [ditto.store collection:@\"people\"];\n[[collection findByID:docID] updateWithBlock:^(DITMutableDocument *doc) {\n [doc[@\"age\"] set:[NSNumber numberWithInt:32]];\n [doc[@\"ownedCars\"] set:DITCounter.new];\n [doc[@\"ownedCars\"].counter incrementBy:1];\n [doc[@\"friends\"] push:@\"Susan\"];\n}];\n\n",
"query-sort": "NSArray *sortedRedCars = [[[[ditto.store collection:@\"cars\"]\n find:@\"color == 'red'\"]\n sort:@\"miles\" direction:DITSortDirectionAscending] exec];\n\n",
"query-limit": "NSArray *sortedAndLimitedRedCars = [[[[[ditto.store collection:@\"cars\"]\n find:@\"color == 'red'\"]\n sort:@\"miles\" direction:DITSortDirectionAscending]\n limit:100] exec];\n\n",
"sync-basic": "\n DITDitto *ditto = [TestHelpers makeDitto];\n\n NSError *error = nil;\n [ditto startSync:&error];\n\n",
"sync-basic": "DITDitto *ditto = [TestHelpers makeDitto];\n\nNSError *error = nil;\n[ditto startSync:&error];\n\n",
"write-transaction": "NSArray *results = [store write:^(DITWriteTransaction *tx) {\n DITScopedWriteTransaction *cars = tx[@\"cars\"];\n DITScopedWriteTransaction *people = tx[@\"people\"];\n DITDocumentID *docID = [[DITDocumentID alloc] initWithValue: @\"abc123\"];\n [people upsert:@{@\"_id\": docID, @\"name\": @\"Susan\"} error:nil];\n [cars upsert:@{@\"make\": @\"Ford\", @\"color\": @\"black\", @\"owner\": docID} error:nil];\n [cars upsert:@{@\"make\": @\"Toyota\", @\"color\": @\"red\", @\"owner\": docID} error:nil];\n}];\n\nSuppressUnusedWarning(results);\n\n",
"sync-observe": "\nDITDitto *ditto = [TestHelpers makeDitto];\n// Register live query to update UI\nDITCollection *collection = [ditto.store collection:@\"cars\"];\nDITLiveQuery *liveQuery = [[collection find:@\"color == 'red'\"]\n observe:^(NSArray<DITDocument *> *docs, DITLiveQueryEvent *event) {\n\n}];\n\n",
"subscribe": "\nDITDitto *ditto = [TestHelpers makeDitto];\n// Register live query to update UI\nDITCollection *collection = [ditto.store collection:@\"cars\"];\nDITSubscription *subscription = [[collection find:@\"color == 'red'\"] subscribe];\n\n",
"sync-observe-local": "\nDITDitto *ditto = [TestHelpers makeDitto];\n// Register live query to update UI\nDITCollection *collection = [ditto.store collection:@\"cars\"];\n\nDITLiveQuery *liveQuery = [[collection find:@\"color == 'red'\"]\n observeLocal:^(NSArray<DITDocument *> *docs, DITLiveQueryEvent *event) {\n\n}];\n\n",
"sync-observe": "DITDitto *ditto = [TestHelpers makeDitto];\n// Register live query to update UI\nDITCollection *collection = [ditto.store collection:@\"cars\"];\nDITLiveQuery *liveQuery = [[collection find:@\"color == 'red'\"]\n observe:^(NSArray<DITDocument *> *docs, DITLiveQueryEvent *event) {\n\n}];\n\n",
"subscribe": "DITDitto *ditto = [TestHelpers makeDitto];\n// Register live query to update UI\nDITCollection *collection = [ditto.store collection:@\"cars\"];\nDITSubscription *subscription = [[collection find:@\"color == 'red'\"] subscribe];\n\n",
"sync-observe-local": "DITDitto *ditto = [TestHelpers makeDitto];\n// Register live query to update UI\nDITCollection *collection = [ditto.store collection:@\"cars\"];\n\nDITLiveQuery *liveQuery = [[collection find:@\"color == 'red'\"]\n observeLocal:^(NSArray<DITDocument *> *docs, DITLiveQueryEvent *event) {\n\n}];\n\n",
"shared-key": "// This is just an example. You should use OpenSSL to generate a unique shared key for every application.\n\nNSString *p256_der_b64 = @\"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgFUUrOkOH52QN+Rr6uDSDsk4hUTcD1eW4mT0UnGGptFehRANCAATJ3fG8TVLQcDwUV18BJJI8efK0hQAjzB3VJeYOVbfOlqnfukVId0V25r/abxwjD3HfHuPsCGEiefzzmkMbjPo9\";\nDITIdentity *identity = [[DITIdentity alloc] initSharedKeyWithAppID:@\"app\" sharedKey:p256_der_b64];\nDITDitto *ditto = [[DITDitto alloc] initWithIdentity:identity];\n\nNSError *error = nil;\nif (![ditto setOfflineOnlyLicenseToken:validLicense error:&error]) {\n NSLog(@\"Error setting license: %@\", error);\n}\n\n",
"online-playground": "// Replace the all-zero app ID with your own app ID\nDITIdentity *identity = [[DITIdentity alloc] initOnlinePlaygroundWithAppID:@\"00000000-0000-4000-0000-000000000000\"\n token:@\"REPLACE_ME_WITH_A_SHARED_TOKEN\"];\nDITDitto *ditto = [[DITDitto alloc] initWithIdentity:identity];\nNSError *error = nil;\n[ditto startSync:&error];\n\n",
"offline-playground": "// Replace the all-zero app ID with your own app ID\nDITIdentity *identity = [[DITIdentity alloc] initOfflinePlaygroundWithAppID:@\"00000000-0000-4000-0000-000000000000\"];\nDITDitto *ditto = [[DITDitto alloc] initWithIdentity:identity];\nNSError *error = nil;\nif (![ditto setOfflineOnlyLicenseToken:validLicense error:&error]) {\n NSLog(@\"Error setting license: %@\", error);\n}\nif (![ditto startSync:&error]) {\n NSLog(@\"Error starting sync: %@\", error);\n}\n[ditto startSync:&error];\n\n",
Expand All @@ -65,7 +65,7 @@
"online-playground": "let ditto = Ditto(identity: DittoIdentity.onlinePlayground(\n // Replace the all-zero app ID with your own app ID\n appID: \"00000000-0000-4000-0000-000000000000\",\n token: \"REPLACE_ME_WITH_A_SHARED_TOKEN\"\n))\ntry! ditto.startSync()\n\n",
"offline-playground": "var ditto = Ditto(identity: DittoIdentity.offlinePlayground(\n // Replace the all-zero app ID with your own app ID\n appID: \"00000000-0000-4000-0000-000000000000\"\n))\ntry! ditto.setOfflineOnlyLicenseToken(validLicense);\ntry! ditto.startSync()\n\n",
"datamodel": "let carsCollection = ditto.store[\"cars\"]\n// or\nlet carsCollection = ditto.store.collection(\"cars\")\n\n",
"attachment": "\n let collection = ditto.store[\"foo\"]\n\n let myImageURL = bundle.url(forResource: \"image\", withExtension: \"png\")!\n\n let metadata = [\"name\": \"my_image.png\"]\n let attachment = collection.newAttachment(\n path: myImageURL.path,\n metadata: metadata\n )!\n\n let docID = try! collection.upsert([\"some\": \"string\", \"my_attachment\": attachment])\n\n // Later, find the document and the fetch the attachment\n\n let doc = collection.findByID(docID).exec()\n let attachmentToken = doc![\"my_attachment\"].attachmentToken!\n\n let fetcher = collection.fetchAttachment(token: attachmentToken) { status in\n switch status {\n case .completed(let fetchedAttachment):\n // Do something with attachment\n break\n default:\n print(\"Unable to fetch attachment\")\n break\n }\n }\n\n",
"attachment": "let collection = ditto.store[\"foo\"]\n\nlet myImageURL = bundle.url(forResource: \"image\", withExtension: \"png\")!\n\nlet metadata = [\"name\": \"my_image.png\"]\nlet attachment = collection.newAttachment(\n path: myImageURL.path,\n metadata: metadata\n)!\n\nlet docID = try! collection.upsert([\"some\": \"string\", \"my_attachment\": attachment])\n\n// Later, find the document and the fetch the attachment\n\nlet doc = collection.findByID(docID).exec()\nlet attachmentToken = doc![\"my_attachment\"].attachmentToken!\n\nlet fetcher = collection.fetchAttachment(token: attachmentToken) { status in\n switch status {\n case .completed(let fetchedAttachment):\n // Do something with attachment\n break\n default:\n print(\"Unable to fetch attachment\")\n break\n }\n}\n\n",
"upsert-default-data": "let docID = try! ditto.store[\"people\"].upsert([\n \"name\": \"Susan\",\n \"age\": 31\n], writeStrategy: .insertDefaultIfAbsent)\n\n",
"upsert-composite-primary-key": "let docID = try! ditto.store[\"people\"].upsert([\n \"_id\": [ \"userId\": \"456abc\", \"workId\": 789 ],\n \"name\": \"Susan\",\n \"age\": 31\n])\nprint(docID) // \"[ \"userId\": \"456abc\", \"workId\": 789 ]\"\n\n",
"upsert-datatypes": "// Insert JSON-compatible data into Ditto\ntry! ditto.store[\"foo\"].upsert([\n \"boolean\": true,\n \"string\": \"Hello World\",\n \"number\": 10,\n \"map\": [\"key\": \"value\"],\n \"array\": [1,2,3],\n \"null\": nil\n])\n\n",
Expand Down Expand Up @@ -217,7 +217,7 @@
"network-remote-ditto": "val transportConfig = DittoTransportConfig()\n\ntransportConfig.connect.tcpServers.add(\"135.1.5.5:12345\")\ntransportConfig.connect.tcpServers.add(\"185.1.5.5:12345\")\n\nditto.startSync()\n\n",
"network-listen": "val transportConfig = DittoTransportConfig()\ntransportConfig.connect.tcpServers.add(\"135.1.5.5:12345\")\ntransportConfig.connect.tcpServers.add(\"185.1.5.5:12345\")\nditto.startSync()\n\n",
"network-multiple-transports": "val transportConfig = DittoTransportConfig()\n// 1. Enable All Peer to Peer Connections\ntransportConfig.enableAllPeerToPeer()\n// 2. Listen for incoming connections on port 4000\ntransportConfig.listen.tcp.enabled = true\ntransportConfig.listen.http.enabled = false\ntransportConfig.listen.tcp.interfaceIp = \"0.0.0.0\"\ntransportConfig.listen.tcp.port = 4000\n// 3. Connect explicitly to remote devices\ntransportConfig.connect.tcpServers.add(\"135.1.5.5:12345\")\ntransportConfig.connect.tcpServers.add(\"185.1.5.5:12345\")\n\nditto.startSync()\n\n",
"network-monitor-conditions": "\n // ... Setting up inside an Activity\n val androidDependencies = DefaultAndroidDittoDependencies(applicationContext)\n val ditto = Ditto(androidDependencies, DittoIdentity.OnlinePlayground(androidDependencies, appID = \"REPLACE_WITH_APP_ID\", token = \"REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN\"))\n ditto.callback = this\n ditto.startSync()\n\n // Now you can observe real time changes to the transport conditions:\n\n class MainActivity : AppCompatActivity(), DittoCallback {\n\n override fun transportConditionDidChange(transportId: Long, condition: TransportCondition) {\n var toastText: String? = null\n if (condition == TransportCondition.TRANSPORT_CONDITION_BLE_DISABLED) {\n toastText = \"BLE disabled\"\n } else if (condition == TransportCondition.TRANSPORT_CONDITION_NO_BLE_CENTRAL_PERMISSION) {\n toastText = \"Permission missing for BLE\"\n } else if (condition == TransportCondition.TRANSPORT_CONDITION_NO_BLE_PERIPHERAL_PERMISSION) {\n toastText = \"Permission missing for BLE\"\n }\n toastText?.let {\n Handler(mainLooper).post {\n Toast.makeText(this, it, Toast.LENGTH_LONG).show()\n }\n }\n }\n }\n\n",
"network-monitor-conditions": "// ... Setting up inside an Activity\nval androidDependencies = DefaultAndroidDittoDependencies(applicationContext)\nval ditto = Ditto(androidDependencies, DittoIdentity.OnlinePlayground(androidDependencies, appID = \"REPLACE_WITH_APP_ID\", token = \"REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN\"))\nditto.callback = this\nditto.startSync()\n\n// Now you can observe real time changes to the transport conditions:\n\nclass MainActivity : AppCompatActivity(), DittoCallback {\n\n override fun transportConditionDidChange(transportId: Long, condition: TransportCondition) {\n var toastText: String? = null\n if (condition == TransportCondition.TRANSPORT_CONDITION_BLE_DISABLED) {\n toastText = \"BLE disabled\"\n } else if (condition == TransportCondition.TRANSPORT_CONDITION_NO_BLE_CENTRAL_PERMISSION) {\n toastText = \"Permission missing for BLE\"\n } else if (condition == TransportCondition.TRANSPORT_CONDITION_NO_BLE_PERIPHERAL_PERMISSION) {\n toastText = \"Permission missing for BLE\"\n }\n toastText?.let {\n Handler(mainLooper).post {\n Toast.makeText(this, it, Toast.LENGTH_LONG).show()\n }\n }\n }\n}\n\n",
"remove-id": "coll.findByID(docID).remove()\n\n",
"remove-query": "val removedDocIDs = coll.find(\"make == 'Honda'\").remove()\n\n"
},
Expand Down Expand Up @@ -252,4 +252,4 @@
"network-multiple-transports": "DittoTransportConfig config = new DittoTransportConfig();\n\n// 1. Enable Peer to Peer Connections\nconfig.enableAllPeerToPeer();\n\n// 2. Listen for incoming connections on port 4000\nDittoListen listen = new DittoListen();\nDittoTcpListenConfig tcpListenConfig = new DittoTcpListenConfig();\ntcpListenConfig.setEnabled(true);\ntcpListenConfig.setInterfaceIp(\"0.0.0.0\");\ntcpListenConfig.setPort(4000);\nlisten.setTcp(tcpListenConfig);\nconfig.setListen(listen);\n// 3. Connect explicitly to remote devices\nDittoConnect connect = new DittoConnect();\nconnect.setTcpServers(Sets.newHashSet(\"135.1.5.5:12345\", \"185.1.5.5:12345\"));\nconfig.setConnect(connect);\n\ntry {\n ditto.startSync();\n} catch(DittoError error) {\n // handle error\n}\n\n",
"network-monitor-conditions": "// Setting up inside an Activity\nDefaultAndroidDittoDependencies androidDependencies = new DefaultAndroidDittoDependencies(getApplicationContext());\nDitto ditto = new Ditto(androidDependencies, new DittoIdentity.OnlinePlayground(androidDependenciesOne, \"REPLACE_WITH_APP_ID\"));\nditto.callback = this;\nditto.startSync();\n\n// Now you can observe real time changes to the transport conditions:\npublic class MainActivity extends AppCompatActivity implements DittoCallback {\n @Override\n public void transportConditionDidChange(@NotNull DittoTransportCondition condition, @NotNull DittoConditionSource transportId) {\n String toastText = null;\n if (condition == DittoTransportCondition.BleDisabled) {\n toastText = \"BLE disabled\";\n } else if (condition == DittoTransportCondition.NoBleCentralPermission) {\n toastText = \"Permission missing for BLE\";\n } else if (condition == DittoTransportCondition.NoBlePeripheralPermission) {\n toastText = \"Permission missing for BLE\";\n }\n\n if (toastText != null) {\n String finalToastText = toastText;\n runOnUiThread(new Runnable() {\n @Override\n public void run() {\n Toast.makeText(MainActivity.this, finalToastText, Toast.LENGTH_LONG).show();\n }\n });\n }\n }\n}\n\n"
}
}
}
2 changes: 1 addition & 1 deletion src/components/ContextSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ContextSwitcher = ({ className }) => {
let [doc] = getCurrentPageInfo();
let platform = tabGroupChoices['platform']
let path = window.location.pathname
if (platform && platform !== doc) {
if (platform && platform !== doc && doc === 'common') {
return history.push(`/${platform}${path}`)
}

Expand Down

0 comments on commit ae5ddf7

Please sign in to comment.