Skip to content

Commit a25e974

Browse files
committed
Added
1 parent 03c0973 commit a25e974

File tree

6 files changed

+75
-34
lines changed

6 files changed

+75
-34
lines changed

.github/workflows/publish.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Node.js Package
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-node@v2
11+
with:
12+
node-version: '12.x'
13+
registry-url: 'https://npm.pkg.github.com'
14+
scope: '@djthorpe'
15+
- run: npm install
16+
- run: npm publish
17+
env:
18+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@djthorpe:registry=https://npm.pkg.github.com

README.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,55 @@ implementation which provides the following classes:
88
* __Model class__: subclass this for your JSON models, and separately define the members of your class;
99
* __View classes__: classes are provided for form, list, button, etc.
1010

11-
## Usage
11+
## Clone
1212

13-
You'll need to use `npm` to install as a dependency in your module:
13+
You'll need to use `npm` to install as a dependency in your module. Here is what
14+
I do on my Mac which has homebrew installed:
1415

1516
```bash
16-
[bash] npm install github:djthorpe/js-framework
17+
[bash] brew install npm
18+
[bash] cd $PROJECTS
19+
[bash] git clone git@github.com:djthorpe/js-framework.git
20+
[bash] cd js-framework
21+
[bash] npm install
1722
```
1823

24+
## Test
25+
26+
## Provider
27+
28+
The provider is used to fetch JSON objects and arrays from a remote REST source, and stores them. To construct a provider with a model class called MyModelClass,
29+
30+
```javascript
31+
import Provider from '@djthorpe/js-framework';
32+
import MyModelClass from './models';
33+
34+
const origin = 'https://awesome-data-service.com/';
35+
const provider = new Provider(MyModelClass,origin);
36+
```
37+
38+
If the __Model__ class is not provided then a plain vanilla object
39+
is used. The origin is also optional.
40+
41+
You can create a request to a remote API using the `request` method, which will
42+
return immediately, whilst firing events,
43+
44+
```javascript
45+
const path = '/api/datasource';
46+
const req = { method: 'GET' };
47+
const userInfo = null;
48+
const interval = 30 * 1000; // Request every 30 seconds
49+
provider.request(path,req,userInfo,interval);
50+
```
51+
52+
The `req`, `userInfo` and `interval` arguments are optional. If you use
53+
an interval, a request is immediately made and then again periodically. To
54+
cancel an interval, call `provider.cancel();`.
55+
56+
The events fired are as followed:
57+
58+
`mvc.provider.added` (sender,object)
59+
`mvc.provider.changed` (sender,object,existing)
60+
`mvc.provider.deleted` (sender,object)
61+
`mvc.provider.completed` (sender,changed)
62+
`mvc.provider.error` (sender,Error)

etc/rpi4b.conf

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

js/provider.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ export default class Provider extends Emitter {
2020
constructor(constructor, origin) {
2121
super();
2222
this.$origin = origin || '';
23-
this.$constructor = typeof constructor === 'function' ? constructor : Object;
23+
this.$constructor = constructor || Object;
2424
this.$objs = new Map();
2525
this.$timer = null;
2626
}
2727

28-
request(url, req, userInfo, interval) {
28+
request(url, req, interval) {
2929
this.cancel();
3030
if (!this.$timer) {
31-
this.$fetch(url, req, userInfo);
31+
this.$fetch(url, req);
3232
}
3333
if (interval) {
34-
this.$timer = setInterval(this.$fetch.bind(this, url, req, userInfo), interval);
34+
this.$timer = setInterval(this.$fetch.bind(this, url, req), interval);
3535
}
3636
}
3737

@@ -42,7 +42,7 @@ export default class Provider extends Emitter {
4242
}
4343
}
4444

45-
$fetch(url, req, userInfo) {
45+
$fetch(url, req) {
4646
let status;
4747
let changed = false;
4848
fetch(this.$origin + url, req)
@@ -76,11 +76,11 @@ export default class Provider extends Emitter {
7676
}
7777
})
7878
.then(() => {
79-
this.dispatchEvent(EVENT_COMPLETED, this, changed, userInfo);
79+
this.dispatchEvent(EVENT_COMPLETED, this, changed);
8080
})
8181
.catch((error) => {
8282
if (error instanceof Error) {
83-
this.dispatchEvent(EVENT_ERROR, this, error, userInfo);
83+
this.dispatchEvent(EVENT_ERROR, this, error);
8484
} else {
8585
throw error;
8686
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)