Skip to content

Commit e63f42d

Browse files
committed
insights added to README
1 parent 5697760 commit e63f42d

File tree

1 file changed

+85
-5
lines changed

1 file changed

+85
-5
lines changed

README.md

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,93 @@
1-
# globular
1+
# Globular
22

3-
Feature-based Javascript framework
3+
Feature-based, view-agnostic Javascript framework
44

55
## A short story
66

7-
Imagine that you have just finished your web application. A brand new stuff based on a popular framework which proves maintainability since there are many developers out there in the jungle who could maintain it.
7+
Imagine that you have just finished your web application. A brand new stuff based on a popular MV* framework which proves maintainability since there are many developers out there in the jungle who could work with it.
88

9-
But time is changing and a new framework is raised. A better one, a modern one and decision is quite obvious: you must port you application. And this is the point when you face the fact that framework you used dominates your application, no chance to simply change the view itself and leaving business logic untouched. You must rewrite the whole application from scratch, only a small set of code could be re-used.
9+
But time is changing and a new framework is raised. A better one, a modern one and decision is quite obvious: you must port you application to this new framework. And this is the point when you face the fact that framework you used dominates your application, no chance to simply change the view itself and leaving business logic untouched. You must rewrite the whole application almost from scratch, only a small set of code could be re-used.
1010

1111
## Globular comes into picture
1212

13-
If your application's core logic could be re-usable, you may save tons of work. And this is what Globular provides you.
13+
But what you want to do is to simply change the view to use something else. If your application's core logic could be re-usable, you may save tons of work.
14+
15+
And this is what Globular provides you.
16+
17+
## How to make it
18+
19+
1. Create a new application
20+
1. Write feature's core as a class in ECMAScript 2015 or older version of ECMAScript
21+
1. Implement views to use model comes from feature
22+
1. Wire them together by plugging views into feature
23+
24+
## Example
25+
26+
/* Create new application */
27+
const calculator = globular.initializeApp('calculator', { persistency: localStorage });
28+
29+
/* Feature core definitions */
30+
class IncrementNumber {
31+
constructor ({persistency}) {
32+
this.persistency = persistency;
33+
}
34+
execute() {
35+
let value = Number(this.persistency.getItem('calculator-value')) || 0;
36+
value += 1;
37+
this.persistency.setItem('calculator-value', value);
38+
return { value, operation:'increment' };
39+
}
40+
}
41+
42+
class DecrementNumber {
43+
constructor ({persistency}) {
44+
this.persistency = persistency;
45+
}
46+
execute() {
47+
let value = Number(this.persistency.getItem('calculator-value')) || 0;
48+
value -= 1;
49+
this.persistency.setItem('calculator-value', value);
50+
return { value, operation:'decrement' };
51+
}
52+
}
53+
54+
class ResetNumber {
55+
constructor ({persistency}) {
56+
this.persistency = persistency;
57+
}
58+
execute() {
59+
let value = 0;
60+
this.persistency.setItem('calculator-value', 0);
61+
return { value, operation:'reset' };
62+
}
63+
}
64+
65+
/* Extending application with features */
66+
calculator.extendWithFeature('increment-number', IncrementNumber);
67+
calculator.extendWithFeature('decrement-number', DecrementNumber);
68+
calculator.extendWithFeature('reset-number', ResetNumber);
69+
70+
/* Initializing view */
71+
const resultIndicator = document.querySelector('#result');
72+
const operationIndicator = document.querySelector('#operation')
73+
document.querySelector('#reset').onclick = () => {
74+
calculator.executeFeature('reset-number');
75+
};
76+
document.querySelector('#increment').onclick = () => {
77+
calculator.executeFeature('increment-number');
78+
};
79+
document.querySelector('#decrement').onclick = () => {
80+
calculator.executeFeature('decrement-number');
81+
};
82+
function updateResult(viewmodel) {
83+
resultIndicator.innerText = viewmodel.value;
84+
}
85+
function updateOperation(viewmodel) {
86+
operationIndicator.innerText = viewmodel.operation;
87+
}
88+
89+
/* Plug-in views into features */
90+
calculator.getFeature('increment-number').pluginView(updateResult).pluginView(updateOperation);
91+
calculator.getFeature('decrement-number').pluginView(updateResult).pluginView(updateOperation);
92+
calculator.getFeature('multiply-number').pluginView(updateResult).pluginView(updateOperation);
93+
calculator.getFeature('reset-number').pluginView(updateResult).pluginView(updateOperation);

0 commit comments

Comments
 (0)