Skip to content

Commit 080688c

Browse files
committed
Markdown documentation added
1 parent e63f42d commit 080688c

File tree

21 files changed

+468
-0
lines changed

21 files changed

+468
-0
lines changed

docs/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Globular
2+
3+
Globular is a feature-based, view-agnostic framework written in ECMAScript 2015 (aka ECMAScript 6). Main goal of it to provide an easy way to separate application's business logic and view, by organizing application functionalities into features at the highest level and by making view to be pluggable into these features.
4+
5+
[Objects in Globular](objects/README.md)
6+
7+
[Interface Definitions](interface/README.md)
8+
9+
[Installation and usage](installation/README.md)
10+
11+
## Changelog
12+
13+
* 0.1.0
14+
1. ability to create Globular apps and extend it by features
15+
1. globular.Api class to provide pluginable API adapter solution for applications

docs/installation/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Installation and usage
2+
3+
[Index](/docs/README.md) | Installation and usage
4+
5+
To install, type following command in terminal:
6+
7+
npm install globular --save
8+
9+
After package is installed, you can refer to it in your application as follows:
10+
11+
class DoImportantThingCore {
12+
execute(data) {
13+
// TODO: implement functionality
14+
}
15+
}
16+
17+
const myApplication = globular.initializeApp('my-app');
18+
myApplication.extendWithFeature('do-important-thing', DoImportantThingCore);
19+
myApplication.executeFeature('do-important-thing', { 'prop1':'value1', 'prop2':2 });
20+
21+
If you need nothing more but an API adapter to use in your exsisting application, just make it happen as follows:
22+
23+
const myApi = new globular.Api();
24+
25+
myApi.pluginCall('get-current-location', () => ({
26+
type: 'xhr',
27+
config: {
28+
url: '/api/get-location',
29+
method: 'get'
30+
}
31+
}));
32+
33+
...
34+
35+
let currentLocation = myApi.request('get-current-location').then((data) => data);

docs/interface/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Interface definitions
2+
3+
[Index](/docs/README.md) | Interface definitions
4+
5+
[Feature Core interface](feature-core/README.md)
6+
7+
[Persistency Adapter interface](persistency-adapter/README.md)
8+
9+
[API Adapter interface](api-adapter/README.md)
10+
11+
[API Request function](api-request/README.md)
12+
13+
[View function](view/README.md)

docs/interface/api-adapter/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## API Adapter interface
2+
3+
[Index](/docs/README.md) | [Interface definitions](/docs/interface/README.md) | API Adapter interface
4+
5+
API Adapter interface is a common way to make API plugginable to applications. When initializing an application, you could define which adapter you prefer to use.
6+
7+
### Criteria against
8+
9+
1. Adapter must have `pluginCall` and `request` methods implemented.
10+
11+
**Example**
12+
13+
class MyApiAdapter {
14+
pluginCall() {}
15+
16+
request(data) {
17+
return JSON.stringify(data);
18+
}
19+
}
20+
21+
*Note that [globular.Api](/docs/objects/framework/api/README.md) implements this interface. Please check section for specialties.*

docs/interface/api-request/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## API Request function
2+
3+
[Index](/docs/README.md) | [Interface definitions](/docs/interface/README.md) | API Request function
4+
5+
API request function is for providing a API call configuration for built-in [API Adapter class](/docs/objects/framework/api) instance based on input parameter. When a feature calls API, API Adapter queries relevant call configuration and run request against API based on configuration.
6+
7+
### Criteria against
8+
9+
Function must return an object with following high-level properties defined:
10+
11+
`type`
12+
13+
String value to define how to handle request. Currently only `'xhr'` type is supported.
14+
15+
`config`
16+
17+
Configuration object, required properties depends on request type specified by `type` property. In case of `type: 'xhr'`, following properties are used:
18+
19+
* `config.method`: HTTP method to use
20+
* `config.url`: requested URL
21+
* `config.headers`: key-value pairs of HTTP headers
22+
* `config.body`: HTTP body
23+
24+
**Example**
25+
26+
(data) => ({
27+
type: 'xhr',
28+
config: {
29+
url: '/api/book-table',
30+
method: 'post',
31+
headers: { 'Allow-Origin': '*' },
32+
body: JSON.stringify(data),
33+
}
34+
})

docs/interface/feature-core/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Feature Core class
2+
3+
[Index](/docs/README.md) | [Interface definitions](/docs/interface/README.md) | Feature Core class
4+
5+
Feature Core class implements application's business logic.
6+
7+
### Criteria against
8+
9+
1. Feature Core must have `execute` methods implemented.
10+
1. If it requires persistency and/or API, constructor must be declared as follows: `constructor({ persistency, api })`
11+
12+
**Example**
13+
14+
class CreateOrder {
15+
constructor({ persistency, api }) {
16+
this.persistency = persistency;
17+
this.api = api;
18+
}
19+
20+
execute(data) {
21+
const apiKey = this.persistency.getItem('api-key');
22+
return this.api.request('create-order', { apiKey, orderName: data.name })
23+
.then(result => result);
24+
}
25+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Persistency Adapter interface
2+
3+
[Index](/docs/README.md) | [Interface definitions](/docs/interface/README.md) | Persistency Adapter interface
4+
5+
Persistency Adapter interface provides a way to build-up a persistency-agnostic application. This interface only defines a few set of methods an Adapter instance must implement and [Feature Core](/docs/interface/feature-core/README.md) must use. These methods are:
6+
7+
1. `getItem(key)`
8+
1. `setItem(key, value)`
9+
1. `removeItem()`
10+
1. `clear()`
11+
12+
As you may notice, these set of methods is a subset of [Storage interface](http://www/w3.org/TR/webstorage/#the-storage-interface) API which let e.g. browser's localStorage object to be injected into applications.
13+
14+
**Example**
15+
16+
const myApplication = globular.initializeApp('calculator', { persistency:localStorage });
17+
18+
class FetchWeatherHere {
19+
constructor({ persistency }) {
20+
this.persistency = persistency;
21+
}
22+
23+
execute(data) {
24+
const cityCode = this.persistency.getItem('current-location');
25+
26+
// do some stuff here
27+
}
28+
}
29+
30+
myApplication.extendWithFeature('fetch-weather-here', FetchWeatherHere);

docs/interface/view/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## View function
2+
3+
[Index](/docs/README.md) | [Interface definitions](/docs/interface/README.md) | View function
4+
5+
View function is a callback added to [Feature](/docs/objects/feature/README.md). When feature executes, generated view-model is passed to each plugged-in view to handle.
6+
7+
*Please note that there is no restriction about what will be passed to this function after feature executed. View-model would be a simple string or an object, relevant feature must determine what kind of view-model is generated.*
8+
9+
**Example**
10+
11+
data => {
12+
document.querySelector('#indicator').innerText = data.label;
13+
}

docs/objects/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Objects in Globular
2+
3+
[Index](/docs/README.md) | Objects in Globular
4+
5+
[Framework](framework/README.md)
6+
7+
[Application](application/README.md)
8+
9+
[Feature](feature/README.md)

docs/objects/application/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Application
2+
3+
[Index](/docs/README.md) | [Objects in Globular](/docs/objects/README.md) | Application
4+
5+
Application object provides ability work with features of application. This includes extending application with a feature, as well as executing a feature.
6+
7+
[getFeature()](get-feature/README.md)
8+
9+
[getFeatures()](get-features/README.md)
10+
11+
[extendWithFeature()](extend-with-feature/README.md)
12+
13+
[executeFeature()](execute-feature/README.md)

0 commit comments

Comments
 (0)