Skip to content

Commit 8e97028

Browse files
authored
feat: cut version 1 (#4)
BREAKING CHANGE: cut version 1.0 * feat: update app-runtime exports, add readmes * docs: add root readme
1 parent 7038a73 commit 8e97028

File tree

8 files changed

+76
-52
lines changed

8 files changed

+76
-52
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
# app-runtime
2-
A singular runtime dependency for applications on the DHIS2 platform
1+
# DHIS2 Application Runtime
32

4-
**WORK IN PROGRESS, DO NOT USE**
3+
See [@dhis2/app-runtime](./runtime) in the `./runtime` directory for installation and usage.
4+
5+
## Development
6+
7+
```sh
8+
> yarn test # runs yarn test on each directory under ./services, and also in ./runtime
9+
> yarn build # runs yarn test on each directory under ./services, and then in ./runtime
10+
```
11+
12+
## Example
13+
14+
A `create-react-app` example is available at [./examples/cra](./examples/cra). Be sure to run `yarn build` in _this_ directory before installing in the example directory:'
15+
16+
```sh
17+
> yarn build
18+
> cd examples/cra && yarn start
19+
# visit http://localhost:3000
20+
# login to https://play.dhis2.org/dev to allow the example to retrieve data
21+
```
22+
23+
## Release
24+
25+
Releases run automatically for every commit to the master branch using the [d2 cli](https://github.com/dhis2/cli).
26+
27+
**NEVER PUSH DIRECTLY TO `master`! ALL DEVELOPMENT IN THIS REPOSITORY IS THROUGH PULL REQUESTS**

examples/cra/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SKIP_PREFLIGHT_CHECK=true

examples/cra/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"start": "react-scripts start",
1313
"build": "react-scripts build",
1414
"test": "react-scripts test",
15-
"eject": "react-scripts eject"
15+
"eject": "react-scripts eject",
16+
"preinstall": "echo \"Run yarn install with --check-files to update local dependency!\""
1617
},
1718
"eslintConfig": {
1819
"extends": "react-app"

examples/cra/src/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React, { Component } from 'react'
22
import './App.css'
3-
import { Query } from '@dhis2/app-runtime'
3+
import { DataQuery } from '@dhis2/app-runtime'
44

55
class App extends Component {
66
render() {
77
return (
88
<div className="App">
99
<header className="App-header">
1010
<h3>Indicators (first 10)</h3>
11-
<Query
11+
<DataQuery
1212
query={{
1313
indicators: {
1414
resource: 'indicators.json',
@@ -30,7 +30,7 @@ class App extends Component {
3030
</pre>
3131
)
3232
}}
33-
</Query>
33+
</DataQuery>
3434
</header>
3535
</div>
3636
)

runtime/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# DHIS2 Application Runtime
2+
3+
A singular runtime dependency for applications on the DHIS2 platform
4+
5+
## Installation
6+
7+
```sh
8+
yarn add @dhis2/app-runtime
9+
```
10+
11+
**NB** Please ensure that all webpack bundles reference the same Context, you can do this by adding `@dhis2/app-runtime` to `peerDependencies` (rather than `dependencies`) and webpack `externals` for _library_ builds. Top-level web applications should be able to include the dependency directly
12+
13+
This library uses the official React Context API (introduced in 16.3) and React Hooks (introduced in 16.8), so **React >= 16.8 is required** to use it
14+
15+
## Usage
16+
17+
The `@dhis2/app-runtime` library is a thin wrapper around application services. See each service's README for usage instructions. Currently, the included services are:
18+
19+
- [data](../services/data) - declarative data fetching for DHIS2 api queries

runtime/bundle.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

runtime/src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export { Provider as DataProvider, Query } from '@dhis2/app-service-data'
1+
export {
2+
Provider as DataProvider,
3+
Query as DataQuery,
4+
useQuery as useDataQuery,
5+
} from '@dhis2/app-service-data'

services/data/README.md

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,29 @@
22

33
## Installation
44

5-
```sh
6-
yarn add @dhis2/app-service-data # ONCE THIS IS PUBLISHED, IT'S NOT YET
7-
```
8-
9-
**NB** Please ensure that all webpack bundles reference the same Context, you can do this by adding `@dhis2/app-service-data` to `peerDependencies` (rather than `dependencies`) and webpack `externals` for _library_ builds. Top-level apps should be able to include the dependency directly
10-
11-
This library uses the official React Context API (introduced in 16.3) and React Hooks (introduced in 16.8), so **React >= 16.8 is required** to use it
5+
This package is internal to `@dhis2/app-runtime` and should not be installed independently. `@dhis2/app-service-data` is not currently published to `npm`. Please install `@dhis2/app-runtime` instead.
126

137
## Usage
148

159
At the top-level application entry point (i.e. `index.js` in Create React App configurations)
1610

1711
```js
18-
import { Provider } from '@dhis2/app-service-data'
12+
import { DataProvider } from '@dhis2/app-runtime'
1913

2014
export default () => (
21-
<Provider baseUrl="localhost:8080" apiVersion={32}>
15+
<DataProvider baseUrl="localhost:8080" apiVersion={32}>
2216
<App />
23-
</Provider>
17+
</DataProvider>
2418
)
2519
```
2620

2721
To request data from a DHIS2 Core server anywhere in the app:
2822

2923
```js
30-
import { Query } from `@dhis2/app-service-data`
24+
import { DataQuery } from `@dhis2/app-runtime`
3125

3226
const MyComponent = () => (
33-
<Query query={{
27+
<DataQuery query={{
3428
me: { resource: 'me' },
3529
indicators: { resource: 'indicators.json', pageSize: 10 }
3630
}}>
@@ -39,29 +33,29 @@ const MyComponent = () => (
3933
if (error) return `ERROR: ${error.message}`
4034
return <div>{JSON.stringify(data)}</div>
4135
}
42-
</Query>
36+
</DataQuery>
4337
)
4438
```
4539

4640
You can also use the cleaner React hooks api:
4741

4842
```js
49-
import { useQuery } from '@dhis2/app-service-data'
43+
import { useDataQuery } from '@dhis2/app-runtime'
5044

5145
const MyComponent = () => {
52-
const { loading, error, data } = useQuery({
53-
me: { resource: 'me' },
54-
indicators: { resource: 'indicators.json', pageSize: 10 }
55-
})
56-
if (loading) return '...'
57-
if (error) return `ERROR: ${error.message}`
58-
return <div>{JSON.stringify(data)}</div>
46+
const { loading, error, data } = useDataQuery({
47+
me: { resource: 'me' },
48+
indicators: { resource: 'indicators.json', pageSize: 10 },
49+
})
50+
if (loading) return '...'
51+
if (error) return `ERROR: ${error.message}`
52+
return <div>{JSON.stringify(data)}</div>
5953
}
60-
```
54+
```
6155

6256
## Known limitations
6357

64-
* Only GET requests are currently supported
65-
* ~`resourcePath` must be a string and cannot be split into `resource`, `query`, etc.~
66-
* The Provider does no data caching or request de-duplication yet
67-
* Data should be normalized (~and requested in a normalizable way~) at the provider level to optimize network requests
58+
- Only GET requests are currently supported
59+
- ~`resourcePath` must be a string and cannot be split into `resource`, `query`, etc.~
60+
- The Provider does no data caching or request de-duplication yet
61+
- Data should be normalized (~and requested in a normalizable way~) at the provider level to optimize network requests

0 commit comments

Comments
 (0)