-
Notifications
You must be signed in to change notification settings - Fork 1
/
keet.js
87 lines (73 loc) · 1.91 KB
/
keet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Keetjs v4.0.0 Alpha release: https://github.com/keetjs/keet
* Minimalist view layer for the web
*
* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Keetjs >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
*
* Copyright 2018, Shahrul Nizam Selamat
* Released under the MIT License.
*/
import parseStr from './src/components/parseStr'
import { updateContext, morpher } from './src/components/genElement'
import { genId, assert, html, createModel } from './utils'
import mount from './src/base/mount'
// window.l = console.log.bind(console)
// window.tr = console.trace.bind(console)
/**
* @description
* The main constructor of Keet
*
* Basic Usage :-
*
* const App extends Keet {}
* const app = new App()
* app.mount('hello world').link('app')
*
*/
class Keet {
constructor () {
this.ID = Keet.indentity
}
// generate ID for the component
static get indentity () {
return genId()
}
mount (instance) {
return mount.call(this, instance)
}
link (id) {
// The target DOM where the rendering will took place.
if (!id) assert(id, 'No id is given as parameter.')
this.el = id
this.render()
return this
}
render (stub) {
// life-cycle method before rendering the component
if (this.componentWillMount && typeof this.componentWillMount === 'function') {
this.componentWillMount()
}
// Render this component to the target DOM
if (stub) {
this.IS_STUB = true
}
parseStr.call(this, stub)
}
callBatchPoolUpdate () {
// force component to update, if any state / non-state
// value changed DOM diffing will occur
updateContext.call(this, morpher, 1)
}
subscribe (fn) {
this.exec = fn
}
inform (model) {
this.exec && typeof this.exec === 'function' && this.exec(model)
}
}
// export default Keet
export {
Keet as default,
html,
createModel
}