-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
4,026 additions
and
5,448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"buildCommand": "compile", | ||
"sandboxes": ["new", "react-typescript-react-ts"], | ||
"node": "14" | ||
"node": "18" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint'], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:import/recommended', | ||
'plugin:import/typescript', | ||
'plugin:react/recommended', | ||
'plugin:react/jsx-runtime', | ||
'plugin:react-hooks/recommended', | ||
'plugin:jsx-a11y/recommended', | ||
'prettier', | ||
], | ||
ignorePatterns: ['dist/'], | ||
settings: { | ||
'import/resolver': { | ||
typescript: true, | ||
}, | ||
react: { version: 'detect' }, | ||
}, | ||
rules: { | ||
'import/no-unresolved': ['error', { ignore: ['valtio-yjs'] }], | ||
'@typescript-eslint/no-unused-vars': [ | ||
'error', | ||
{ | ||
args: 'all', | ||
argsIgnorePattern: '^_', | ||
caughtErrors: 'all', | ||
caughtErrorsIgnorePattern: '^_', | ||
destructuredArrayIgnorePattern: '^_', | ||
varsIgnorePattern: '^_', | ||
ignoreRestSiblings: true, | ||
}, | ||
], | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/pnpm-lock.yaml | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
"printWidth": 140, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": false, | ||
"singleQuote": false, | ||
"trailingComma": "all", | ||
"bracketSpacing": true, | ||
"jsxBracketSameLine": true, | ||
"fluid": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<title>example</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "example", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"dependencies": { | ||
"react": "latest", | ||
"react-dom": "latest", | ||
"valtio": "latest", | ||
"valtio-yjs": "latest", | ||
"y-websocket": "latest" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "latest", | ||
"@types/react-dom": "latest", | ||
"typescript": "latest", | ||
"vite": "latest" | ||
}, | ||
"scripts": { | ||
"dev": "vite" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as Y from 'yjs'; | ||
import { WebsocketProvider } from 'y-websocket'; | ||
import { bind } from 'valtio-yjs'; | ||
import { proxy, useSnapshot } from 'valtio'; | ||
import { useState } from 'react'; | ||
|
||
const ydoc = new Y.Doc(); | ||
|
||
new WebsocketProvider('wss://demos.yjs.dev', 'valtio-yjs-demo', ydoc); | ||
|
||
const ymap = ydoc.getMap('messages.v1'); | ||
const mesgMap = proxy({} as Record<string, string>); | ||
bind(mesgMap, ymap); | ||
|
||
const MyMessage = () => { | ||
const [name, setName] = useState(''); | ||
const [message, setMessage] = useState(''); | ||
const send = () => { | ||
if (name && message) { | ||
mesgMap[name] = message; | ||
} | ||
}; | ||
return ( | ||
<div> | ||
<div> | ||
Name: <input value={name} onChange={(e) => setName(e.target.value)} /> | ||
</div> | ||
<div> | ||
Message:{' '} | ||
<input value={message} onChange={(e) => setMessage(e.target.value)} /> | ||
</div> | ||
<button disabled={!name || !message} onClick={send}> | ||
Send | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
const Messages = () => { | ||
const snap = useSnapshot(mesgMap); | ||
return ( | ||
<div> | ||
{Object.keys(snap) | ||
.reverse() | ||
.map((key) => ( | ||
<p key={key}> | ||
{key}: {snap[key]} | ||
</p> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
const App = () => ( | ||
<div> | ||
<h2>My Message</h2> | ||
<MyMessage /> | ||
<h2>Messages</h2> | ||
<Messages /> | ||
</div> | ||
); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { StrictMode } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
import App from './app'; | ||
|
||
createRoot(document.getElementById('root')!).render( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode>, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"target": "es2018", | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "bundler", | ||
"skipLibCheck": true, | ||
"allowJs": true, | ||
"noUncheckedIndexedAccess": true, | ||
"exactOptionalPropertyTypes": true, | ||
"jsx": "react-jsx" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<title>example</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "example", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"dependencies": { | ||
"react": "latest", | ||
"react-dom": "latest", | ||
"valtio": "latest", | ||
"valtio-yjs": "latest", | ||
"y-websocket": "latest" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "latest", | ||
"@types/react-dom": "latest", | ||
"typescript": "latest", | ||
"vite": "latest" | ||
}, | ||
"scripts": { | ||
"dev": "vite" | ||
} | ||
} |
Oops, something went wrong.