Skip to content

Commit

Permalink
fix: various
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon committed May 31, 2022
1 parent ed3258d commit 9c0a603
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
20 changes: 10 additions & 10 deletions example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { OrbitProvider, useOrbitDb } from "../../src";

window.LOG = "*";

const ORBIT_DB_EVENTS =
"/orbitdb/zdpuB2cZqW3mNmAM1tZ6mNPpcw6bSdNKNgPw4ppqJpnjS8Teg/react-ortbitdb-eventlog";
const ORBIT_DB_EVENTS = "react-ortbitdb-eventlog";
//"/orbitdb/zdpuB2cZqW3mNmAM1tZ6mNPpcw6bSdNKNgPw4ppqJpnjS8Teg/react-ortbitdb-eventlog";

const ORBIT_DB_DOCS =
"/orbitdb/zdpuAknUxcYsKArW2d8KtBhwyLfkmADo4wpwmC8ReKy3Q5pDR/react-ortbitdb-docstore";
const ORBIT_DB_DOCS = "react-ortbitdb-docstore";
//"/orbitdb/zdpuAknUxcYsKArW2d8KtBhwyLfkmADo4wpwmC8ReKy3Q5pDR/react-ortbitdb-docstore";

const ORBIT_DB_KEYVALUE =
"/orbitdb/zdpuAod4qh5m3SmjuSVtLUEspqp1yCQABWm1iEdSPFDQ5mUkU/react-ortbitdb-keyvalue";
const ORBIT_DB_KEYVALUE = "react-ortbitdb-keyvalue";
//"/orbitdb/zdpuAod4qh5m3SmjuSVtLUEspqp1yCQABWm1iEdSPFDQ5mUkU/react-ortbitdb-keyvalue";

const ORBIT_DB_COUNTER =
"/orbitdb/zdpuAzbF3ZzhMsbtw4vkKoP1BEcH1CbgE1fRMUuykQdcbHe7X/react-ortbitdb-counter";
const ORBIT_DB_COUNTER = "react-ortbitdb-counter";
//"/orbitdb/zdpuAzbF3ZzhMsbtw4vkKoP1BEcH1CbgE1fRMUuykQdcbHe7X/react-ortbitdb-counter";

const Intro = () => (
<div className="jumbotron">
Expand Down Expand Up @@ -312,10 +312,10 @@ const CounterDemo = () => {
return (
<div>
<p style={{ fontSize: "0.8em" }}>
{(value && `Connected to ${ORBIT_DB_COUNTER}`) ||
{(value !== undefined && `Connected to ${ORBIT_DB_COUNTER}`) ||
`Connecting to ${ORBIT_DB_COUNTER}...`}
</p>
{value && (
{value !== undefined && (
<h1>
<span
className="badge badge-primary"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"clean": "rm -rf ./dist",
"clean:demo": "rm -rf ./example/dist",
"start": "parcel watch ./src/index.js --out-dir ./dist",
"start:demo": "parcel ./example/src/index.html --out-dir ./example/dist",
"start:demo": "parcel serve ./example/src/index.html --out-dir ./example/dist",
"build": "yarn run build:browser && yarn run build:cjs && yarn run build:esm",
"build:browser": "parcel build ./src/index.js --global react-orbitdb",
"build:cjs": "BABEL_ENV=cjs babel src --out-dir cjs",
Expand Down
4 changes: 2 additions & 2 deletions src/ipfs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const DEFAULT_IPFS_CONFIG = {
preload: {
enabled: false,
},
repo: "./some-repo",
repo: "./example",
EXPERIMENTAL: { pubsub: true },
config: {
Bootstrap: [
// "/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
//"/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
// "/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3",
// "/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
// "/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
Expand Down
20 changes: 16 additions & 4 deletions src/useOrbitDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,26 @@ const useOrbitDb = (address, options = {}) => {
if (!address) return;

const createDb = async () => {
logger.debug("orbit.create", address);

const allOptions = {
indexBy: "id",
create: false,
create: true, // doesnt really work ?
type: "keyvalue",
overwrite: false,
...options,
// options.public controls write access
// // options.public controls write access
...(options.create && options.public
? publicWrite(orbit)
: publicRead(orbit)),
};
logger.debug("orbit.open", address, allOptions);
const db = await orbit.open(address, allOptions);
const dbAddress = await orbit.determineAddress(
address,
allOptions.type,
allOptions
);
logger.debug("orbit.open", dbAddress, allOptions);
const db = await orbit.open(dbAddress, allOptions);
logger.debug("orbitdb.opened", db.address.toString());
const refreshDb = async () => {
await db.load();
Expand Down Expand Up @@ -75,6 +82,11 @@ const useOrbitDb = (address, options = {}) => {
logger.debug("db.events.write", address.toString());
refreshDb();
});

db.events.on("error", (err) => {
logger.debug("db.events.error", err);
refreshDb();
});
await refreshDb();
};
if (orbit) {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2800,9 +2800,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001043:
version "1.0.30001078"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001078.tgz#e1b6e2ae327b6a1ec11f65ec7a0dde1e7093074c"
integrity sha512-sF12qXe9VMm32IEf/+NDvmTpwJaaU7N1igpiH2FdI4DyABJSsOqG3ZAcFvszLkoLoo1y6VJLMYivukUAxaMASw==
version "1.0.30001344"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001344.tgz"
integrity sha512-0ZFjnlCaXNOAYcV7i+TtdKBp0L/3XEU2MF/x6Du1lrh+SRX4IfzIVL4HNJg5pB2PmFb8rszIGyOvsZnqqRoc2g==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit 9c0a603

Please sign in to comment.