Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/irislib/iris
https://github.com/irislib/iris
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/irislib/iris
- Owner: irislib
- Created: 2024-03-27T10:03:33.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-06-03T09:48:47.000Z (8 months ago)
- Last Synced: 2024-07-12T10:49:50.969Z (6 months ago)
- Language: TypeScript
- Size: 959 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-starred - irislib/iris - Iris project description (others)
README
IrisDB
======
IrisDB is a simple treelike data structure with subscribable nodes. It can be easily synced over different transports.
For example, it provides a very simple way for local state management in React applications. The state can be optionally persisted in localStorage or synced between browser tabs.Similarly, it can be used for "public state" management to synchronize with other users and devices. You can easily build all kinds of decentralized applications where accounts are public keys.
See it in action on [docs.iris.to](https://docs.iris.to/).
It's inspired by [GunDB](https://github.com/amark/gun) and has a similar API.
[Documentation](https://irisdb.iris.to/)
## Installation
Just IrisDB, e.g. local use:
```
npm install irisdb
```With Nostr:
```
npm install @nostr-dev-kit/ndk @nostr-dev-kit/ndk-cache-dexie nostr-tools irisdb irisdb-nostr
```React hooks:
```
npm install @nostr-dev-kit/ndk @nostr-dev-kit/ndk-cache-dexie nostr-tools irisdb irisdb-nostr irisdb-hooks
```(non-irisdb libs are peer dependencies)
## Examples
### Persist React app local state in localStorage and sync between tabs
```tsx
import { useLocalState } from 'irisdb-hooks';function LoginDialog() {
const [myPrivateKey, setMyPrivateKey] = useLocalState('user/privateKey', '');
function onChange(e) {
const val = e.target.value;
if (val.length === 64) {
setMyPrivateKey(val);
}
}if (!myPrivateKey) {
return (
);
}
return (
Logged in
setMyPrivateKey('')}>Log out
);
}
```### Collaborative document editing
Uses the `irisdb-nostr` adapter to sync over [Nostr](https://nostr.com).
```tsx
import { usePublicState, useAuthors } from 'irisdb-hooks';function DocumentTitle() {
// List of users you follow on Nostr.
// Alternatively, provide an array of public keys.
const authors = useAuthors('follows');
const titlePath = 'apps/canvas/documents/myDocument1/title';
const [docName, setDocName] = usePublicState(authors, titlePath, 'Untitled Document');
return (
setDocName(e.target.value)} placeholder="Document title" />
);
}
```