Skip to content

Commit 831a950

Browse files
committed
added parcel example.
1 parent a675005 commit 831a950

File tree

14 files changed

+1481
-54
lines changed

14 files changed

+1481
-54
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/*
2+
examples/**/node_modules/*

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ node_modules
88
# Jetbrains IDE project files
99
.idea
1010

11+
# Bundler artifacts
12+
.cache
13+
dist
14+

examples/.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true
4+
},
5+
"parserOptions": {
6+
"sourceType": "module"
7+
}
8+
};

examples/horrible_example.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ function pprint(obj)
1919
const db = trivialdb.db('example', { writeToDisk: false });
2020

2121
// Create some new keys
22-
let hammerID, horribleID, moistID, bhSingerID, pennyID;
22+
let hammerID; let horribleID; let moistID; let bhSingerID; let pennyID;
2323
Promise.resolve()
2424
.then(() =>
2525
{
2626
return Promise.join(
27-
db.save({ name: "Captain Hammer", role: 'hero', nemeses: [] }).then((id) => { hammerID = id; }),
28-
db.save({ name: "Dr. Horrible", role: 'villain', nemeses: [] }).then((id) => { horribleID = id; }),
29-
db.save({ name: "Moist", role: 'henchman', nemeses: [] }).then((id) => { moistID = id; }),
30-
db.save({ name: "Bad Horse Singer", role: 'henchman', nemeses: [] }).then((id) => { bhSingerID = id; }),
31-
db.save({ name: "Penny", role: 'love interest', nemeses: [] }).then((id) => { pennyID = id; })
27+
db.save({ name: 'Captain Hammer', role: 'hero', nemeses: [] }).then((id) => { hammerID = id; }),
28+
db.save({ name: 'Dr. Horrible', role: 'villain', nemeses: [] }).then((id) => { horribleID = id; }),
29+
db.save({ name: 'Moist', role: 'henchman', nemeses: [] }).then((id) => { moistID = id; }),
30+
db.save({ name: 'Bad Horse Singer', role: 'henchman', nemeses: [] }).then((id) => { bhSingerID = id; }),
31+
db.save({ name: 'Penny', role: 'love interest', nemeses: [] }).then((id) => { pennyID = id; })
3232
);
3333
})
3434
.then(() =>
@@ -40,7 +40,7 @@ Promise.resolve()
4040
{
4141
// Update some values
4242
const hammer = db.get(hammerID);
43-
hammer.nemeses = [horribleID];
43+
hammer.nemeses = [ horribleID ];
4444
hammer.loveInterest = pennyID;
4545

4646
return db.save(hammer);
@@ -49,7 +49,7 @@ Promise.resolve()
4949
{
5050
// Update some values
5151
const horrible = db.get(horribleID);
52-
horrible.nemeses = [hammerID];
52+
horrible.nemeses = [ hammerID ];
5353
horrible.loveInterest = pennyID;
5454
return db.save(horrible);
5555
})
@@ -83,6 +83,15 @@ Promise.resolve()
8383

8484
// Print out everyone who loves Penny
8585
console.log('\n[Step 3] Henchmen who hench for Dr. Horrible:\n%s', pprint(horribleHenches));
86+
})
87+
.then(() =>
88+
{
89+
// Find every henchman who henches for Dr. Horrible
90+
const bhSingers = db.get(bhSingerID)
91+
.run();
92+
93+
// Print out everyone who loves Penny
94+
console.log('\n[Step 4] Details on the Bad Horse Singers:\n%s', pprint(bhSingers));
8695
});
8796

8897
//----------------------------------------------------------------------------------------------------------------------

examples/parcel/Readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# TrivialDB Webpack Example
2+
3+
This is a very simple example demonstrating using TrivialDB inside of a webpack project. Basically, there's no work to
4+
actually do; simple import TrivialDB and use it. There is no special webpack configuration, or other requirements.
5+
6+
It just works™.
7+
8+
## Reading and Writing
9+
10+
By default, it will attempt to load (via a `GET` request) from `/db/database_name.json`. Writes will make a `POST` to
11+
the same url. As an example, this project loads `/db/books.json`. Since it does not use a node server, however, it does
12+
not support writing.
13+
14+
If you want to do something different (like have your data come from inside the bundle, removing latency), you can use
15+
the `readFunc` and `writeFunc` options. The `users` test in this project is a demonstration of that.
16+
17+
## Running the Demo
18+
19+
Just run `npm run dev`, and open [http://localhost:555](http://localhost:555).

0 commit comments

Comments
 (0)