Skip to content

Commit 2a85fa0

Browse files
committed
[docs] Import guide
1 parent b182895 commit 2a85fa0

File tree

5 files changed

+99
-17
lines changed

5 files changed

+99
-17
lines changed

site/guides/1_the_basics/1_getting_started.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,9 @@ If that all worked, you are set up and ready to learn more about TinyBase! From
8282
here on, we will mostly show Node-based code snippets, but most should be easily
8383
translatable to run in a browser too.
8484

85+
Before we move on, you should be aware that the overall package includes a
86+
number of different versions of TinyBase, transpiled for different targets and
87+
formats. You may want to take a look at the Importing TinyBase guide if the code
88+
above isn't working in your environment - React Native in particular.
89+
8590
Let's move onto the Creating A Store guide.

site/guides/1_the_basics/6_transactions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ console.log(store.getTables());
108108
We've covered all of the essential basics of working with a TinyBase Store, but
109109
that's still just the start!
110110

111-
Next we will show how you can quickly build user interfaces on top of a Store,
112-
and for that, it's time to proceed to the Building UIs guide.
111+
Before we move on, we have a quick aside about how to use various flavors of
112+
TinyBase in your app, in the Importing TinyBase guide.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Importing TinyBase
2+
3+
This guide provides a quick aside about importing TinyBase into your
4+
application.
5+
6+
## Targets and formats
7+
8+
The overall package includes a number of different versions of TinyBase,
9+
transpiled for different targets and formats. You'll find them all in the
10+
`./lib` folder of the package, and you can directly import them as follows:
11+
12+
| Directory | Target | Format | Minified | Import |
13+
| ----------- | ------ | ------ | -------- | ------------------------------------ |
14+
| lib | esnext | esm | yes | `import {...} from tinybase` |
15+
| lib/debug | esnext | esm | no | `import {...} from tinybase/debug` |
16+
| lib/umd | esnext | umd | yes | `import {...} from tinybase/umd` |
17+
| lib/cjs | esnext | cjs | yes | `import {...} from tinybase/cjs` |
18+
| lib/es6 | es6 | esm | yes | `import {...} from tinybase/es6` |
19+
| lib/umd-es6 | es6 | umd | yes | `import {...} from tinybase/umd-es6` |
20+
| lib/cjs-es6 | es6 | cjs | yes | `import {...} from tinybase/cjs-es6` |
21+
22+
## Using TinyBase submodules
23+
24+
The tinybase module is the master package of all the functionality together
25+
(except the ui-react module and tools module, which always remain standalone
26+
options). Since many of the submodules share compiled-in dependencies, the
27+
master package is smaller to include than including all of the submodules
28+
separately.
29+
30+
However, for a very minimal set of submodules, you may save size by including
31+
them piecemeal. If you only wanted a Store and a Metrics object, for example,
32+
you could import them alone like this:
33+
34+
```js yolo
35+
import {createStore} from 'tinybase/store';
36+
import {createMetrics} from 'tinybase/metrics';
37+
// ...
38+
```
39+
40+
You can also import single packages in other targets and formats. For example:
41+
42+
```js yolo
43+
import {createStore} from 'tinybase/es6/store';
44+
import {createMetrics} from 'tinybase/es6/metrics';
45+
import {useCell} from 'tinybase/es6/ui-react';
46+
// ...
47+
```
48+
49+
## React Native
50+
51+
If you are using [React Native](https://reactnative.dev/) - for example with
52+
[Expo](https://expo.dev/) - be aware that the
53+
[Metro](https://facebook.github.io/metro/) bundler does not currently support
54+
module resolution very well. You may have to add in the `lib` portion of the
55+
path to be explicit about your imports:
56+
57+
```js yolo
58+
import {createStore} from 'tinybase/lib';
59+
import {useCell} from 'tinybase/lib/ui-react';
60+
```
61+
62+
OK, enough with the `import` shenanigans. Next we will show how you can quickly
63+
build user interfaces on top of a Store, and for that, it's time to proceed to
64+
the Building UIs guide.

site/guides/2_building_uis/1_getting_started_with_ui_react.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,17 @@ are merely to support JSX in the browser and for the purposes of illustrating
4444
how to get started quickly. In a production environment you should pre-compile
4545
and your JSX and modules to create a bundled browser app.
4646

47-
Let's first understand how to use hooks in the ui-react module, and move on to
48-
the Using React Hooks guide.
47+
If you're bundling the whole app, you can of course import the ui-react module
48+
something like this:
49+
50+
```js yolo
51+
import {createStore} from 'tinybase';
52+
import {CellView} from 'tinybase/ui-react';
53+
// ...
54+
```
55+
56+
(You can also select different targets and flavors of the ui-react module as
57+
described in the Importing TinyBase guide.)
58+
59+
Boilerplate aside, let's move on to understand how to use hooks in the ui-react
60+
module, with the Using React Hooks guide.

site/guides/8_how_tinybase_is_built/2_architecture.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ the `.d.ts` type definitions, the compiled `.js` files, and their compressed
6464
submodules.
6565

6666
The `tinybase.js` and `tinybase.js.gz` files represent the master package of
67-
everything together (except the ui-react module, which always remains a
68-
standalone option). Since many of the submodules share compiled-in dependencies,
69-
the master package is smaller to include than including all of the submodules
70-
separately. However, for a very minimal set of modules, you may save size by
71-
including them piecemeal.
67+
everything together (except the ui-react module and tools module, which always
68+
remain standalone options). Since many of the submodules share compiled-in
69+
dependencies, the master package is smaller to include than including all of the
70+
submodules separately. However, for a very minimal set of modules, you may save
71+
size by including them piecemeal.
7272

7373
In the root of the `lib` directory, all of these files are built to the
7474
[`esnext`](https://esbuild.github.io/api/#target) target and the
@@ -77,13 +77,14 @@ are subdirectories that contain builds of different types:
7777

7878
| Directory | Target | Format | Minified |
7979
| --------- | ------ | ------ | -------- |
80-
| . | esnext | esm | true |
81-
| ./debug | esnext | esm | false |
82-
| ./umd | esnext | umd | true |
83-
| ./cjs | esnext | cjs | true |
84-
| ./es6 | es6 | esm | true |
85-
| ./umd-es6 | es6 | umd | true |
86-
| ./cjs-es6 | es6 | cjs | true |
80+
| . | esnext | esm | yes |
81+
| ./debug | esnext | esm | no |
82+
| ./umd | esnext | umd | yes |
83+
| ./cjs | esnext | cjs | yes |
84+
| ./es6 | es6 | esm | yes |
85+
| ./umd-es6 | es6 | umd | yes |
86+
| ./cjs-es6 | es6 | cjs | yes |
8787

8888
These build configurations are all defined in the `compileForProd` task in
89-
`gulpfile.mjs`.
89+
`gulpfile.mjs`, and instructions for importing them are in the Importing
90+
TinyBase guide.

0 commit comments

Comments
 (0)