Skip to content

Commit 1a2b0c3

Browse files
committed
use prettier
1 parent 3909d33 commit 1a2b0c3

31 files changed

+1859
-1173
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"array-callback-return": 1,
1313
"no-eval": 1,
1414
"one-var": ["warn", "never"],
15+
"indent": ["warn", 2, { "SwitchCase": 1 }],
1516
"wrap-iife": 1,
1617
"no-loop-func": 1,
1718
"no-duplicate-imports": 1,

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = grunt => {
2828
watch: grunt.file.readJSON('tasks/watch.json'),
2929
clean: grunt.file.readJSON('tasks/clean.json'),
3030
eslint: grunt.file.readJSON('tasks/eslint.json'),
31-
jsbeautifier: grunt.file.readJSON('tasks/jsbeautifier.json'),
31+
prettier: grunt.file.readJSON('tasks/prettier.json'),
3232
mocha_istanbul: grunt.file.readJSON('tasks/mocha_istanbul.json'),
3333
karma: grunt.file.readJSON('tasks/karma.json'),
3434
browserify: grunt.file.readJSON('tasks/browserify.json'),
@@ -54,7 +54,7 @@ module.exports = grunt => {
5454
'clean',
5555
'json_merge',
5656
'concat:system',
57-
'jsbeautifier',
57+
'prettier',
5858
'eslint',
5959
'mocha_istanbul:coverage',
6060
'browserify:debug',

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,28 @@
4242
"coveralls": "grunt coveralls"
4343
},
4444
"devDependencies": {
45+
"chai": "^4.1.2",
46+
"coveralls": "^3.0.0",
4547
"grunt": "^1.0.1",
46-
"grunt-cli": "^1.2.0",
4748
"grunt-browserify": "^5.2.0",
49+
"grunt-cli": "^1.2.0",
4850
"grunt-contrib-clean": "^1.1.0",
4951
"grunt-contrib-concat": "^1.0.1",
5052
"grunt-contrib-uglify": "^3.2.1",
5153
"grunt-contrib-watch": "^1.0.0",
5254
"grunt-eslint": "^20.1.0",
53-
"grunt-jsbeautifier": "^0.2.13",
5455
"grunt-json-merge": "^0.2.2",
5556
"grunt-karma": "^2.0.0",
5657
"grunt-mocha-istanbul": "^5.0.2",
57-
"load-grunt-tasks": "^3.5.2",
58-
"chai": "^4.1.2",
59-
"mocha": "^4.0.1",
60-
"coveralls": "^3.0.0",
58+
"grunt-prettier": "^0.3.1",
6159
"istanbul": "^0.4.5",
6260
"karma": "^1.7.1",
61+
"karma-chai": "^0.1.0",
6362
"karma-chrome-launcher": "^2.2.0",
6463
"karma-coverage": "^1.1.1",
65-
"karma-chai": "^0.1.0",
6664
"karma-mocha": "^1.3.0",
67-
"karma-script-launcher": "^1.0.0"
65+
"karma-script-launcher": "^1.0.0",
66+
"load-grunt-tasks": "^3.5.2",
67+
"mocha": "^4.0.1"
6868
}
69-
}
69+
}

src/behavior.js

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
* limitations under the License.
1919
*/
2020

21-
/**
21+
/**
2222
* @module behavior
2323
* @requires db
2424
* @requires helper
2525
* @requires channel
26-
* @description This module manages the behaviors of all components.
27-
* A behavior is a mecanism that allow users to add actions that will be executed
26+
* @description This module manages the behaviors of all components.
27+
* A behavior is a mecanism that allow users to add actions that will be executed
2828
* when a specific state of a component will change.
2929
*/
3030

@@ -33,20 +33,15 @@
3333
var $db = require('./db.js');
3434
var $helper = require('./helper.js');
3535

36-
3736
/* Private properties */
3837

39-
4038
var store = {};
4139

42-
4340
/* Private methods */
4441

45-
46-
4742
/**
4843
* @method createFunction
49-
* @param {String} name default name of the function
44+
* @param {String} name default name of the function
5045
* @param {String} func a stringified function
5146
* @param {Boolean} core if true, the behavior will be treated as a System Runtime core behavior.
5247
* In that case, the behavior can not be exported in a system (default false)
@@ -81,7 +76,10 @@ function createFunction(name, func, core, useCoreAPI) {
8176
header = header.replace('=>', '');
8277

8378
if (header.indexOf('(') !== -1) {
84-
funcParams = header.split('(')[1].replace(')', '').trim();
79+
funcParams = header
80+
.split('(')[1]
81+
.replace(')', '')
82+
.trim();
8583
} else {
8684
funcParams = header.trim();
8785
}
@@ -108,7 +106,10 @@ function createFunction(name, func, core, useCoreAPI) {
108106
beginBody = func.indexOf('{');
109107
header = func.substring(0, beginBody);
110108

111-
funcParams = header.split('(')[1].replace(')', '').trim();
109+
funcParams = header
110+
.split('(')[1]
111+
.replace(')', '')
112+
.trim();
112113

113114
params = funcParams.split(',');
114115
params.forEach(function(param) {
@@ -133,23 +134,35 @@ function createFunction(name, func, core, useCoreAPI) {
133134
}
134135

135136
if (params[0] !== '') {
136-
action = new Function('__body', "return function " + name + " (" + params.join(',') + ") { return new Function('" + params.join("','") + "', __body).apply(this, arguments) };")(funcBody);
137+
action = new Function(
138+
'__body',
139+
'return function ' +
140+
name +
141+
' (' +
142+
params.join(',') +
143+
") { return new Function('" +
144+
params.join("','") +
145+
"', __body).apply(this, arguments) };"
146+
)(funcBody);
137147
} else {
138-
action = new Function('__body', "return function " + name + " () { return new Function(__body).apply(this, arguments) };")(funcBody);
148+
action = new Function(
149+
'__body',
150+
'return function ' +
151+
name +
152+
' () { return new Function(__body).apply(this, arguments) };'
153+
)(funcBody);
139154
}
140155

141156
return action;
142157
}
143158

144-
145159
/* Public methods */
146160

147-
148161
/**
149162
* @method add
150163
* @param {String} id id of the component
151-
* @param {Object} state the state on which the action will be executed
152-
* @param {Object} action the action to execute when the component will have a specific state
164+
* @param {Object} state the state on which the action will be executed
165+
* @param {Object} action the action to execute when the component will have a specific state
153166
* @param {Boolean} useCoreAPI if true, System Runtime core modules will be injected as parameters of the action (default false)
154167
* @param {Boolean} core if true, behavior can not be exported
155168
* @returns {String} id of the behavior created in System Runtime database
@@ -171,18 +184,17 @@ exports.add = function add(id, state, action, useCoreAPI, core) {
171184
store[behaviorId] = action;
172185

173186
$db._Behavior.insert({
174-
'_id': behaviorId,
175-
'component': id,
176-
'state': state,
177-
'action': strAction,
178-
'useCoreAPI': useCoreAPI,
179-
'core': core
187+
_id: behaviorId,
188+
component: id,
189+
state: state,
190+
action: strAction,
191+
useCoreAPI: useCoreAPI,
192+
core: core
180193
});
181194

182195
return behaviorId;
183196
};
184197

185-
186198
/**
187199
* @method remove
188200
* @param {Object} params
@@ -203,20 +215,20 @@ exports.remove = function remove(params) {
203215
if (params.componentId) {
204216
if (params.behaviorId) {
205217
$db._Behavior.remove({
206-
'_id': params.behaviorId,
207-
'component': params.componentId,
208-
'state': params.state
218+
_id: params.behaviorId,
219+
component: params.componentId,
220+
state: params.state
209221
});
210222
delete store[params.behaviorId];
211223
} else {
212224
if (params.state) {
213225
result = $db._Behavior.remove({
214-
'component': params.componentId,
215-
'state': params.state
226+
component: params.componentId,
227+
state: params.state
216228
});
217229
} else {
218230
result = $db._Behavior.remove({
219-
'component': params.componentId
231+
component: params.componentId
220232
});
221233
}
222234
result.forEach(function(id) {
@@ -226,7 +238,6 @@ exports.remove = function remove(params) {
226238
}
227239
};
228240

229-
230241
/**
231242
* @method removeFromMemory
232243
* @param {String} id id of the component
@@ -236,7 +247,6 @@ exports.removeFromMemory = function removeFromMemory(id) {
236247
delete store[id];
237248
};
238249

239-
240250
/**
241251
* @method getActions
242252
* @param {String} id id of the component
@@ -250,26 +260,30 @@ exports.getActions = function getActions(id, state) {
250260
var action = null;
251261

252262
dbResult = $db._Behavior.find({
253-
'component': id,
254-
'state': state
263+
component: id,
264+
state: state
255265
});
256266

257267
dbResult.forEach(function(behavior) {
258268
action = store[behavior._id];
259269
if (typeof action === 'undefined') {
260-
action = createFunction(behavior.state, behavior.action, behavior.core, behavior.useCoreAPI);
270+
action = createFunction(
271+
behavior.state,
272+
behavior.action,
273+
behavior.core,
274+
behavior.useCoreAPI
275+
);
261276
store[behavior._id] = action;
262277
}
263278
result.push({
264-
'useCoreAPI': behavior.useCoreAPI,
265-
'action': action
279+
useCoreAPI: behavior.useCoreAPI,
280+
action: action
266281
});
267282
});
268283

269284
return result;
270285
};
271286

272-
273287
/**
274288
* @method clear
275289
* @description Remove all the behaviors stored in memory
@@ -278,7 +292,6 @@ exports.clear = function clear() {
278292
store = {};
279293
};
280294

281-
282295
/**
283296
* @method get
284297
* @param {String} id id of the behavior

0 commit comments

Comments
 (0)