Completed
Push — master ( a2efde...24c14a )
by Thomas
49s
created

_.debounce   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 11
rs 9.4285
1
'use strict'
2
3
const minimatch = require('minimatch')
4
const _ = require('lodash')
5
const request = require('../util').request
6
const Module = require('../containers/Module')
7
8
const reload = _.debounce(function (containerToken, path, event) {
9
  request(containerToken + '/ws', {
10
    type: 'autoreload',
11
    payload: {
12
      path: path,
13
      event: event
14
    }
15
  }, {
16
    'Content-Type': 'multipart/form-data'
17
  }).end()
18
}, 120)
19
20
module.exports = function (containerToken, path, event) {
21
  Module.getManifest(function (manifest) {
22
    var options = manifest.getDevOption('autoreload')
23
    if (!options || !('paths' in options)) {
24
      return
25
    }
26
    if (typeof options.paths === 'string') {
27
      options.paths = [options.paths]
28
    }
29
30
    var matched = false
31
    for (var i in options.paths) {
32
      if (!options.paths.hasOwnProperty(i)) {
33
        continue
34
      }
35
      if (minimatch(path, options.paths[i])) {
36
        matched = true
37
        break
38
      }
39
    }
40
41
    if (!matched) {
42
      return
43
    }
44
45
    reload(containerToken, path, event)
46
  })
47
}
48