Skip to content

Commit 9799701

Browse files
committed
Clean code
1 parent a2b03c2 commit 9799701

21 files changed

+101
-107
lines changed

extensions/README.md

100644100755
File mode changed.

extensions/mode-admin-server.json

100644100755
Lines changed: 25 additions & 25 deletions
Large diffs are not rendered by default.

extensions/mode-admin.json

100644100755
Lines changed: 33 additions & 33 deletions
Large diffs are not rendered by default.

extensions/mode-dev.json

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"_id": "y1c59d1de591d81e",
1111
"component": "z1f9151698514d13",
1212
"state": "start",
13-
"action": "() => {\n if (typeof document !== 'undefined') {\n document.addEventListener('dragenter', function dragenter(e) {\n e.stopPropagation();\n e.preventDefault();\n }, false);\n\n document.addEventListener('dragover', function dragover(e) {\n e.stopPropagation();\n e.preventDefault();\n }, false);\n\n document.addEventListener('drop', function drop(e) {\n e.stopPropagation();\n e.preventDefault();\n var files = e.dataTransfer.files;\n var reader = new FileReader();\n var json = '';\n reader.onload = function onload(event) {\n json += event.target.result;\n };\n reader.onloadend = function onloadend() {\n var sys = JSON.parse(json);\n runtime.install(sys);\n };\n reader.readAsText(files[0], 'UTF-8');\n });\n }\n};",
13+
"action": "function start() {\n if (typeof document !== 'undefined') {\n document.addEventListener('dragenter', function dragenter(e) {\n e.stopPropagation();\n e.preventDefault();\n }, false);\n\n document.addEventListener('dragover', function dragover(e) {\n e.stopPropagation();\n e.preventDefault();\n }, false);\n\n document.addEventListener('drop', function drop(e) {\n e.stopPropagation();\n e.preventDefault();\n var files = e.dataTransfer.files;\n var reader = new FileReader();\n var json = '';\n reader.onload = function onload(event) {\n json += event.target.result;\n };\n reader.onloadend = function onloadend() {\n var sys = JSON.parse(json);\n runtime.install(sys);\n };\n reader.readAsText(files[0], 'UTF-8');\n });\n }\n}",
1414
"useCoreAPI": false,
1515
"core": false
1616
}

extensions/storage.json

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,39 @@
2424
"_id": "1ca0f1020412d4f",
2525
"component": "_Storage",
2626
"state": "get",
27-
"action": "(key) => {\n var result = null;\n\n if (typeof this.store()[key]) {\n result = this.store()[key];\n }\n return result;\n}",
27+
"action": "function get(key) {\n var result = null;\n\n if (typeof this.store()[key]) {\n result = this.store()[key];\n }\n return result;\n}",
2828
"useCoreAPI": false,
2929
"core": true
3030
},
3131
"16764100d51b5f8": {
3232
"_id": "16764100d51b5f8",
3333
"component": "_Storage",
3434
"state": "set",
35-
"action": "(key, value) => {\n var store = this.store(),\n item = {};\n\n store[key] = value;\n this.store(store);\n\n item[key] = JSON.stringify(value);\n\n try {\n switch (true) {\n case typeof localStorage !== 'undefined':\n localStorage.setItem(key, JSON.stringify(value));\n break;\n default:\n break;\n }\n } catch (e) { }\n}",
35+
"action": "function set(key, value) {\n var store = this.store(),\n item = {};\n\n store[key] = value;\n this.store(store);\n\n item[key] = JSON.stringify(value);\n\n try {\n switch (true) {\n case typeof localStorage !== 'undefined':\n localStorage.setItem(key, JSON.stringify(value));\n break;\n default:\n break;\n }\n } catch (e) { }\n}",
3636
"useCoreAPI": false,
3737
"core": true
3838
},
3939
"134b616b1016f60": {
4040
"_id": "134b616b1016f60",
4141
"component": "_Storage",
4242
"state": "clear",
43-
"action": "() => {\n this.store({});\n try {\n switch (true) {\n case typeof localStorage !== 'undefined':\n localStorage.clear();\n break;\n default:\n break;\n }\n } catch (e) { }\n}",
43+
"action": "function clear() {\n this.store({});\n try {\n switch (true) {\n case typeof localStorage !== 'undefined':\n localStorage.clear();\n break;\n default:\n break;\n }\n } catch (e) { }\n}",
4444
"useCoreAPI": false,
4545
"core": true
4646
},
4747
"14c7f1a8431b3d5": {
4848
"_id": "14c7f1a8431b3d5",
4949
"component": "_Storage",
5050
"state": "init",
51-
"action": "(conf) => {\n try {\n switch (true) {\n case typeof localStorage !== 'undefined':\n // init \n var keys = Object.keys(localStorage),\n store = {},\n i = 0,\n length = 0;\n\n length = keys.length;\n for (i = 0; i < length; i++) {\n try {\n store[keys[i]] = JSON.parse(localStorage[keys[i]]);\n } catch (e) { }\n }\n this.store(store);\n\n // event\n window.addEventListener('storage', function (e) {\n var obj = {},\n store = this.store();\n\n try {\n store[e.key] = JSON.parse(e.newValue);\n this.store(store);\n\n obj[e.key] = {};\n obj[e.key].oldValue = JSON.parse(e.oldValue);\n obj[e.key].newValue = JSON.parse(e.newValue);\n\n this.changed(obj);\n } catch (e) { }\n }.bind(this));\n break;\n default:\n break;\n }\n } catch (e) { }\n}",
51+
"action": "function init(conf) {\n try {\n switch (true) {\n case typeof localStorage !== 'undefined':\n // init \n var keys = Object.keys(localStorage),\n store = {},\n i = 0,\n length = 0;\n\n length = keys.length;\n for (i = 0; i < length; i++) {\n try {\n store[keys[i]] = JSON.parse(localStorage[keys[i]]);\n } catch (e) { }\n }\n this.store(store);\n\n // event\n window.addEventListener('storage', function (e) {\n var obj = {},\n store = this.store();\n\n try {\n store[e.key] = JSON.parse(e.newValue);\n this.store(store);\n\n obj[e.key] = {};\n obj[e.key].oldValue = JSON.parse(e.oldValue);\n obj[e.key].newValue = JSON.parse(e.newValue);\n\n this.changed(obj);\n } catch (e) { }\n }.bind(this));\n break;\n default:\n break;\n }\n } catch (e) { }\n}",
5252
"useCoreAPI": false,
5353
"core": true
5454
},
5555
"1a4921ac7112bd4": {
5656
"_id": "1a4921ac7112bd4",
5757
"component": "_Storage",
5858
"state": "remove",
59-
"action": "(key) => {\n var store = this.store();\n\n delete store[key];\n this.store(store);\n\n try {\n switch (true) {\n case typeof localStorage !== 'undefined':\n localStorage.removeItem(key);\n break;\n default:\n break;\n }\n } catch (e) { }\n}",
59+
"action": "function remove(key) {\n var store = this.store();\n\n delete store[key];\n this.store(store);\n\n try {\n switch (true) {\n case typeof localStorage !== 'undefined':\n localStorage.removeItem(key);\n break;\n default:\n break;\n }\n } catch (e) { }\n}",
6060
"useCoreAPI": false,
6161
"core": true
6262
}

src/behavior.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ var store = {};
6262
* @private
6363
*/
6464
function createFunction(name, func, core, useCoreAPI) {
65-
var funcName = '',
66-
beginBody = -1,
65+
var beginBody = -1,
6766
funcParams = '',
6867
params = [],
6968
paramsClean = [],
@@ -107,13 +106,10 @@ function createFunction(name, func, core, useCoreAPI) {
107106
if (isArrowFunction && isOneLine && funcBody.indexOf('return ') === -1) {
108107
funcBody = 'return ' + funcBody;
109108
}
110-
111-
funcName = name;
112109
} else {
113110
beginBody = func.indexOf('{');
114111
header = func.substring(0, beginBody);
115112

116-
funcName = header.split('(')[0].replace('function', '').trim();
117113
funcParams = header.split('(')[1].replace(')', '').trim();
118114

119115
params = funcParams.split(',');
@@ -123,8 +119,6 @@ function createFunction(name, func, core, useCoreAPI) {
123119

124120
funcBody = func.substring(beginBody + 1);
125121
funcBody = funcBody.substring(0, funcBody.lastIndexOf('}')).trim();
126-
127-
funcName = funcName || name;
128122
}
129123

130124
if (params[0] === '') {
@@ -142,11 +136,11 @@ function createFunction(name, func, core, useCoreAPI) {
142136

143137
if (params[0] !== '') {
144138
/* jshint -W054 */
145-
action = new Function('__body', "return function " + funcName + " (" + params.join(',') + ") { return new Function('" + params.join("','") + "', __body).apply(this, arguments) };")(funcBody);
139+
action = new Function('__body', "return function " + name + " (" + params.join(',') + ") { return new Function('" + params.join("','") + "', __body).apply(this, arguments) };")(funcBody);
146140
/* jshint +W054 */
147141
} else {
148142
/* jshint -W054 */
149-
action = new Function('__body', "return function " + funcName + " () { return new Function(__body).apply(this, arguments) };")(funcBody);
143+
action = new Function('__body', "return function " + name + " () { return new Function(__body).apply(this, arguments) };")(funcBody);
150144
/* jshint +W054 */
151145
}
152146

src/systems/classes/_Behavior-class.json

100644100755
File mode changed.

src/systems/classes/_Channel-class.json

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@
8989
"_id": "12e491859c13918",
9090
"component": "_Channel",
9191
"state": "$systemStarted",
92-
"action": "(id) => { \n var systems = null;\n \n if (id !== 'e89c617b6b15d24') {\n if (typeof document !== 'undefined') {\n systems = document.querySelectorAll('link[rel=system]');\n \n if ($state.get('runtime') && $state.get('runtime').state === 'ready') { \n } else {\n if (systems.length + 1 === $db._System.count()) {\n $component.get('runtime').ready();\n }\n }\n }\n }\n};",
92+
"action": "function $systemStarted(id) { \n var systems = null;\n \n if (id !== 'e89c617b6b15d24') {\n if (typeof document !== 'undefined') {\n systems = document.querySelectorAll('link[rel=system]');\n \n if ($state.get('runtime') && $state.get('runtime').state === 'ready') { \n } else {\n if (systems.length + 1 === $db._System.count()) {\n $component.get('runtime').ready();\n }\n }\n }\n }\n}",
9393
"useCoreAPI": true,
9494
"core": true
9595
},
9696
"1e9021bd4e1bc6e": {
9797
"_id": "1e9021bd4e1bc6e",
9898
"component": "_Channel",
9999
"state": "$systemInstalled",
100-
"action": "(id) => {\n var systems = null,\n dependencies = [],\n master = [],\n canStart = true;\n\n if (id !== 'e89c617b6b15d24') {\n // if all systems are installed\n systems = $db._System.find({});\n\n systems.forEach(function (system) {\n var sys = this.require(system._id);\n if (sys && sys.state && sys.state() === 'none') {\n canStart = false;\n }\n }.bind(this));\n\n // start all the systems\n if (canStart) {\n dependencies = $db._System.find({\n 'master': false\n });\n\n dependencies.forEach(function (dep) {\n var system = this.require(dep._id);\n channel = this.require('channel');\n\n if (system.state() === 'resolved') {\n system.state('starting');\n system.start();\n channel.$systemStarted(dep._id);\n system.state('active');\n }\n }.bind(this));\n\n master = $db._System.find({\n 'master': true\n });\n\n master.forEach(function (dep) {\n var system = this.require(dep._id);\n channel = this.require('channel');\n\n if (system && system.state && system.state() === 'resolved') {\n system.state('starting');\n system.start();\n channel.$systemStarted(dep._id);\n system.state('active');\n }\n }.bind(this));\n }\n }\n};",
100+
"action": "function $systemInstalled(id) {\n var systems = null,\n dependencies = [],\n master = [],\n canStart = true;\n\n if (id !== 'e89c617b6b15d24') {\n // if all systems are installed\n systems = $db._System.find({});\n\n systems.forEach(function (system) {\n var sys = this.require(system._id);\n if (sys && sys.state && sys.state() === 'none') {\n canStart = false;\n }\n }.bind(this));\n\n // start all the systems\n if (canStart) {\n dependencies = $db._System.find({\n 'master': false\n });\n\n dependencies.forEach(function (dep) {\n var system = this.require(dep._id);\n channel = this.require('channel');\n\n if (system.state() === 'resolved') {\n system.state('starting');\n system.start();\n channel.$systemStarted(dep._id);\n system.state('active');\n }\n }.bind(this));\n\n master = $db._System.find({\n 'master': true\n });\n\n master.forEach(function (dep) {\n var system = this.require(dep._id);\n channel = this.require('channel');\n\n if (system && system.state && system.state() === 'resolved') {\n system.state('starting');\n system.start();\n channel.$systemStarted(dep._id);\n system.state('active');\n }\n }.bind(this));\n }\n }\n}",
101101
"useCoreAPI": true,
102102
"core": true
103103
}

src/systems/classes/_ClassInfo-class.json

100644100755
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,70 @@
88
"_id": "155141e40312cd8",
99
"component": "_ClassInfo",
1010
"state": "collection",
11-
"action": "(name) => {\n var result = {};\n if (this.schema()[name] === 'collection') {\n result = this.model()[name];\n }\n\n return result;\n};",
11+
"action": "function collection(name) {\n var result = {};\n if (this.schema()[name] === 'collection') {\n result = this.model()[name];\n }\n\n return result;\n}",
1212
"core": true
1313
},
1414
"1f6941a0c012c1f": {
1515
"_id": "1f6941a0c012c1f",
1616
"component": "_ClassInfo",
1717
"state": "collections",
18-
"action": "(name) => {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'collection') {\n result.push(item);\n }\n }\n\n return result;\n};",
18+
"action": "function collections(name) {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'collection') {\n result.push(item);\n }\n }\n\n return result;\n}",
1919
"core": true
2020
},
2121
"1ef711b4171c849": {
2222
"_id": "1ef711b4171c849",
2323
"component": "_ClassInfo",
2424
"state": "event",
25-
"action": "(name) => {\n var result = {};\n\n if (this.schema()[name] === 'event') {\n result = this.model()[name];\n }\n\n return result;\n}",
25+
"action": "function event(name) {\n var result = {};\n\n if (this.schema()[name] === 'event') {\n result = this.model()[name];\n }\n\n return result;\n}",
2626
"core": true
2727
},
2828
"1bae51b6ed1d25c": {
2929
"_id": "1bae51b6ed1d25c",
3030
"component": "_ClassInfo",
3131
"state": "events",
32-
"action": "(name) => {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'event') {\n result.push(item);\n }\n }\n return result;\n};",
32+
"action": "function events(name) {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'event') {\n result.push(item);\n }\n }\n return result;\n}",
3333
"core": true
3434
},
3535
"19ac2125221528b": {
3636
"_id": "19ac2125221528b",
3737
"component": "_ClassInfo",
3838
"state": "link",
39-
"action": "(name) => {\n var result = {};\n\n if (this.schema()[name] === 'link') {\n result = this.model()[name];\n }\n return result;\n}",
39+
"action": "function link(name) {\n var result = {};\n\n if (this.schema()[name] === 'link') {\n result = this.model()[name];\n }\n return result;\n}",
4040
"core": true
4141
},
4242
"17ed21dfc01b8e8": {
4343
"_id": "17ed21dfc01b8e8",
4444
"component": "_ClassInfo",
4545
"state": "links",
46-
"action": "(name) => {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'link') {\n result.push(item);\n }\n } return result;\n};",
46+
"action": "function links(name) {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'link') {\n result.push(item);\n }\n } return result;\n}",
4747
"core": true
4848
},
4949
"11ce318a561ac61": {
5050
"_id": "11ce318a561ac61",
5151
"component": "_ClassInfo",
5252
"state": "method",
53-
"action": "(name) => {\n var result = {};\n if (this.schema()[name] === 'method') {\n result = this.model()[name];\n }\n \n return result;\n}",
53+
"action": "function method(name) {\n var result = {};\n if (this.schema()[name] === 'method') {\n result = this.model()[name];\n }\n \n return result;\n}",
5454
"core": true
5555
},
5656
"12ff2190a018046": {
5757
"_id": "12ff2190a018046",
5858
"component": "_ClassInfo",
5959
"state": "methods",
60-
"action": "(name) => {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'method') {\n result.push(item);\n }\n }\n\n return result;\n};",
60+
"action": "function methods(name) {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'method') {\n result.push(item);\n }\n }\n\n return result;\n}",
6161
"core": true
6262
},
6363
"1028d1681e1fd58": {
6464
"_id": "1028d1681e1fd58",
6565
"component": "_ClassInfo",
6666
"state": "properties",
67-
"action": "(name) => {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'property') {\n result.push(item);\n }\n } return result;\n};",
67+
"action": "function properties(name) {\n var keys = Object.keys(this.schema()),\n item = '',\n result = [],\n i = 0,\n length = keys.length;\n\n for (i = 0; i < length; i++) {\n item = keys[i];\n if (this.schema()[item] === 'property') {\n result.push(item);\n }\n } return result;\n}",
6868
"core": true
6969
},
7070
"18eeb10c5319368": {
7171
"_id": "18eeb10c5319368",
7272
"component": "_ClassInfo",
7373
"state": "property",
74-
"action": "(name) => {\n var result = {};\n\n if (this.schema()[name] === 'property') {\n result = this.model()[name];\n }\n return result;\n};",
74+
"action": "function property(name) {\n var result = {};\n\n if (this.schema()[name] === 'property') {\n result = this.model()[name];\n }\n return result;\n}",
7575
"core": true
7676
}
7777
},

0 commit comments

Comments
 (0)