-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example web apps for testing (#72)
* parcel web app for testing * example webpack app for testing * eslint typings
- Loading branch information
Showing
14 changed files
with
5,481 additions
and
994 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
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules/ | |
*.tgz | ||
.vscode/ | ||
.env | ||
.parcel-cache/ |
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 |
---|---|---|
|
@@ -11,4 +11,5 @@ yarn.lock | |
tests/ | ||
bin/ | ||
.env | ||
.circleci/ | ||
.circleci/ | ||
.parcel-cache/ |
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 @@ | ||
export type Character = { | ||
id: string; | ||
name: string; | ||
affiliation: string; | ||
age: number; | ||
}; | ||
|
||
export const characters = [ | ||
{ | ||
id: '1', | ||
name: 'Darth Vader', | ||
affiliation: 'Sith', | ||
age: 30, | ||
}, | ||
{ | ||
id: '2', | ||
name: 'Yoda', | ||
affiliation: 'Jedi', | ||
age: 900, | ||
}, | ||
{ | ||
id: '3', | ||
name: 'Darth Sidius', | ||
affiliation: 'Sith', | ||
age: 65, | ||
}, | ||
{ | ||
id: '4', | ||
name: 'Obi-Wan Kenobi', | ||
affiliation: 'Jedi', | ||
age: 68, | ||
}, | ||
{ | ||
id: '5', | ||
name: 'Qui-Gon Jin', | ||
affiliation: 'Jedi', | ||
age: 38, | ||
}, | ||
]; |
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,51 @@ | ||
import { addRxPlugin, createRxDatabase } from 'rxdb'; | ||
import { getRxStorageDexie } from 'rxdb/plugins/storage-dexie'; | ||
import { RxDBQueryBuilderPlugin } from 'rxdb/plugins/query-builder'; | ||
import { RxDBDevModePlugin } from 'rxdb/plugins/dev-mode'; | ||
|
||
import { characters } from './data'; | ||
|
||
addRxPlugin(RxDBDevModePlugin); | ||
addRxPlugin(RxDBQueryBuilderPlugin); | ||
|
||
const initialize = async () => { | ||
// create RxDB | ||
const db = await createRxDatabase({ | ||
name: 'test_database', | ||
storage: getRxStorageDexie(), | ||
ignoreDuplicate: true, | ||
}); | ||
|
||
// create a collection | ||
const collection = await db.addCollections({ | ||
characters: { | ||
schema: { | ||
title: 'characters', | ||
version: 0, | ||
type: 'object', | ||
primaryKey: 'id', | ||
properties: { | ||
id: { | ||
type: 'string', | ||
maxLength: 250, | ||
}, | ||
name: { | ||
type: 'string', | ||
}, | ||
affiliation: { | ||
type: 'string', | ||
}, | ||
age: { | ||
type: 'integer', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await collection.characters.bulkInsert(characters); | ||
|
||
return db; | ||
}; | ||
|
||
export default initialize; |
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,31 @@ | ||
import React from 'react'; | ||
import { useRxData } from '../../src'; | ||
import { Character } from '../data'; | ||
|
||
function App() { | ||
const { result: characters, isFetching } = useRxData<Character>( | ||
'characters', | ||
collection => | ||
collection?.find({ | ||
selector: { | ||
affiliation: 'Jedi', | ||
}, | ||
}) | ||
); | ||
|
||
if (isFetching) { | ||
return <div>loading characters...</div>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<ul> | ||
{characters.map((character, idx) => ( | ||
<li key={idx}>{character.name}</li> | ||
))} | ||
</ul> | ||
</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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>rxdb-hooks</title> | ||
<script type="module" src="./index.tsx"></script> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</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 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { render } from 'react-dom'; | ||
import { RxDatabase } from 'rxdb'; | ||
import { Provider } from '../../src'; | ||
import initialize from '../initialize'; | ||
import App from './App'; | ||
|
||
const Root = () => { | ||
const [db, setDb] = useState<RxDatabase>(); | ||
|
||
useEffect(() => { | ||
initialize().then(setDb); | ||
}, []); | ||
|
||
return ( | ||
<Provider db={db}> | ||
<App /> | ||
</Provider> | ||
); | ||
}; | ||
|
||
render(<Root />, document.getElementById('root')); |
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,31 @@ | ||
import React from 'react'; | ||
import { useRxData } from '../../src'; | ||
import { Character } from '../data'; | ||
|
||
function App() { | ||
const { result: characters, isFetching } = useRxData<Character>( | ||
'characters', | ||
collection => | ||
collection?.find({ | ||
selector: { | ||
affiliation: 'Jedi', | ||
}, | ||
}) | ||
); | ||
|
||
if (isFetching) { | ||
return <div>loading characters...</div>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<ul> | ||
{characters.map((character, idx) => ( | ||
<li key={idx}>{character.name}</li> | ||
))} | ||
</ul> | ||
</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 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Webpack App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</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 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { render } from 'react-dom'; | ||
import { RxDatabase } from 'rxdb'; | ||
import { Provider } from '../../src'; | ||
import initialize from '../initialize'; | ||
import App from './App'; | ||
|
||
const Root = () => { | ||
const [db, setDb] = useState<RxDatabase>(); | ||
|
||
useEffect(() => { | ||
initialize().then(setDb); | ||
}, []); | ||
|
||
return ( | ||
<Provider db={db}> | ||
<App /> | ||
</Provider> | ||
); | ||
}; | ||
|
||
render(<Root />, document.getElementById('root')); |
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,34 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const path = require('path'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
|
||
const config = { | ||
mode: 'development', | ||
entry: path.resolve(__dirname, './index.tsx'), | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
}, | ||
devServer: { | ||
open: true, | ||
host: 'localhost', | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
template: path.resolve(__dirname, './index.html'), | ||
}), | ||
], | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(ts|tsx)$/i, | ||
loader: 'ts-loader', | ||
exclude: ['/node_modules/'], | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.tsx', '.ts', '...'], | ||
}, | ||
}; | ||
|
||
module.exports = config; |
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
Oops, something went wrong.