-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.js
109 lines (88 loc) · 2.11 KB
/
class.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require('Ext')
Ext('Ext.Ext-more', 'Ext.ComponentMgr')
const registry = require(`${__dirname}/var/registry.json`)
,pregistry = require(`${__dirname}/var/plugin.registry.json`)
/**
* @class Ext
*/
// FIXME: Document these methods properly
// private
function applyPluginRegistry() {
Ext.intercept(Ext.ComponentMgr, 'createPlugin', function(a, b) {
let pt = a.ptype || b
if (!this.ptypes[pt]) {
Ext(pregistry[pt])
}
}, Ext.ComponentMgr)
}
Ext.plugin && applyPluginRegistry()
/**
* @param {Object} config
* @return {Object}
*/
Ext.class = function ExtCls(config) {
var base = config.parent || Object
,funcs = config.funcs || {}
,cls
if (config.init) {
funcs.constructor = config.init(function() { let a = Array.from(arguments); (base.superclass ? base.superclass.constructor : base).apply(a[0], a.slice(1)) })
}
cls = Ext.extend(base, funcs)
if (config.xtype) {
Ext.reg(config.xtype, cls)
}
return cls
}
/**
* Initialize configuration given an xtype, using a built-in registry to dynamically load the required source files before initializing the class
* @param {Object} cfg
* @param {Constructor} def Default type
*/
Ext.xcreate = function(cfg, def) {
if (!def && !cfg.xtype) {
// Make code simpler, we probably just got an actual object, so return that
return cfg
}
if (!Ext.ComponentMgr.isRegistered(cfg.xtype)) {
Ext(registry[cfg.xtype])
}
return Ext.create(cfg, def)
}
/**
* Initialize all plugins on a component
* @param {Object} cmp Component with plugins to initialize
*/
Ext.psetup = function(cmp) {
Ext('Ext.plugin')
applyPluginRegistry()
return Ext.psetup(cmp)
}
// Private function to enable co-operative modules to add stuff to xcreate()
Ext.xcreate.reg = function(key, module) {
registry[key] = module
}
/*
var A, C
A = Ext.class({
init: function(sup) {
return function() { sup(this); this.x = 42 }
}
,xtype: 'A'
})
Ext.reg('B', function() {
this.x = 1337
})
Ext.class({
init: function(sup) {
return function() {
sup(this)
this.y = 'foobar'
}
}
,xtype: 'C'
,parent: A
})
console.dir(['A', 'B', 'C'].map((cls) => {
return Ext.create({xtype: cls})
}))
*/