Skip to content

Commit 905ad54

Browse files
committed
Renamed Add to define and added dispatch started event for provider
1 parent 3fd7706 commit 905ad54

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

js/controller.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import View from './view';
55
import Provider from './provider';
66
import CopyPaste from './copypaste';
77

8+
/**
9+
* Controller which acts as business logic between models, views and
10+
* providers. In general, create a new controller using the New
11+
* static method and then define properties of the controller. Call
12+
* main to run the application.
13+
* @class
14+
*/
815
export default class Controller {
916
constructor() {
1017
this.$providers = new Map();
@@ -28,7 +35,13 @@ export default class Controller {
2835
});
2936
}
3037

31-
Add(key, object) {
38+
/**
39+
* Define a view or provider for the controller. The object is then
40+
* accessible as a property of the controller.
41+
* @param {string} key - The name of the property
42+
* @param {Provider|View} object - The object
43+
*/
44+
define(key, object) {
3245
if (!key || this.$providers.has(key) || this.$views.has(key)) {
3346
throw Error(`Controller: Duplicate or invalid key ${key}`);
3447
}
@@ -47,6 +60,10 @@ export default class Controller {
4760
});
4861
}
4962

63+
/**
64+
* Create and return a new controller
65+
* @param {Controller} constructor - The constructor for the controller
66+
*/
5067
static New(constructor) {
5168
const C = constructor || Controller;
5269
if (C.prototype instanceof Controller) {

js/provider.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Emitter from './emitter';
77
// CONSTANTS
88

99
const EVENT_ROOT = 'mvc.provider';
10+
const EVENT_STARTED = `${EVENT_ROOT}.started`;
1011
const EVENT_COMPLETED = `${EVENT_ROOT}.completed`;
1112
const EVENT_ERROR = `${EVENT_ROOT}.error`;
1213
const EVENT_ADDED = `${EVENT_ROOT}.added`;
@@ -16,6 +17,10 @@ const EVENT_DELETED = `${EVENT_ROOT}.deleted`;
1617
// ////////////////////////////////////////////////////////////////////////////
1718
// PROVIDER CLASS
1819

20+
/**
21+
* Provider requests data from a remote endpoint.
22+
* @class
23+
*/
1924
export default class Provider extends Emitter {
2025
constructor(constructor, origin) {
2126
super();
@@ -45,6 +50,7 @@ export default class Provider extends Emitter {
4550
$fetch(url, req) {
4651
let status;
4752
let changed = false;
53+
this.dispatchEvent(EVENT_STARTED, this, this.$origin + url);
4854
fetch(this.$origin + url, req)
4955
.then((response) => {
5056
status = response;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@djthorpe/js-framework",
3-
"version": "0.0.11",
3+
"version": "0.0.12",
44
"description": "Javascript UI Framework",
55
"main": "dist/js/index.js",
66
"scripts": {
@@ -17,7 +17,7 @@
1717
"registry": "https://npm.pkg.github.com"
1818
},
1919
"author": "David Thorpe",
20-
"license": "ISC",
20+
"license": "Apache",
2121
"bugs": {
2222
"url": "https://github.com/djthorpe/js-framework/issues"
2323
},

0 commit comments

Comments
 (0)