lib/Execution/Context.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.17

Size

Lines of Code 77
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
wmc 7
nc 1
mnd 1
bc 7
fnc 6
dl 0
loc 77
rs 10
bpm 1.1666
cpm 1.1666
noi 0
c 2
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B Context.js ➔ Context 0 46 1
1
var Slf4j = require('@ama-team/voxengine-sdk').Logger.Slf4j
2
3
/**
4
 * @typedef {object} Context~Options
5
 *
6
 * @property
7
 * @property {object} [arguments]
8
 * @property {object} [container]
9
 * @property {object} [state]
10
 * @property {LoggerOptions|IVarArgLogger} [logger]
11
 */
12
13
/**
14
 * This class is used as `this` for user-supplied and framework functions,
15
 * literally being execution context.
16
 *
17
 * @param {Run} run
18
 * @param {Context~Options} [options]
19
 *
20
 * @class
21
 *
22
 * @implements IExecutionContext
23
 *
24
 * @property {object} arguments
25
 * @property {object} state
26
 * @property {object} container
27
 */
28
function Context (run, options) {
29
  options = options || {}
30
31
  var name = 'ama-team.vsf.execution.context'
32
  var logger = Slf4j.factory(options.logger, name)
33
  var self = this
34
35
  this.arguments = options.arguments || options.args || {}
36
  this.container = options.container || {}
37
  this.state = options.state || options.data || {}
38
  this.trigger = null
39
40
  /**
41
   * @deprecated
42
   * @property {object} args
43
   */
44
45
  /**
46
   * @deprecated
47
   * @property {object} data
48
   */
49
  Object.defineProperties(this, {
50
    data: {
51
      get: function () {
52
        return self.state
53
      }
54
    },
55
    args: {
56
      get: function () {
57
        return self.arguments
58
      }
59
    }
60
  })
61
62
  Object.keys(logger).forEach(function (method) {
63
    if (typeof logger[method] !== 'function') { return }
64
    self[method] = function () {
65
      var target = self.logger || logger
66
      target[method].apply(target, arguments)
67
    }
68
  })
69
70
  this.transitionTo = function (id, hints) {
71
    return run.transitionTo(id, hints)
72
  }
73
}
74
75
module.exports = {
76
  Context: Context
77
}
78