Files
stf-DeviceFarmer/res/app/device-list/empty/device-list-empty-directive.js
Gunther Brunner 1eb6af0119 Replaced old jade with new pug.
Using temporarily npm-shrinkwrap since `template-html-loader` uses an old `consolidate.js` version which doesn't support `pug`.
Follow here: https://github.com/jtangelder/template-html-loader/issues/8
2016-08-05 18:24:30 +09:00

36 lines
846 B
JavaScript

module.exports = function DeviceListEmptyDirective() {
return {
restrict: 'E'
, template: require('./device-list-empty.pug')
, scope: {
tracker: '&tracker'
}
, link: function(scope) {
var tracker = scope.tracker()
scope.empty = !tracker.devices.length
function update() {
var oldEmpty = scope.empty
var newEmpty = !tracker.devices.length
if (oldEmpty !== newEmpty) {
scope.$apply(function() {
scope.empty = newEmpty
})
}
}
tracker.on('add', update)
tracker.on('change', update)
tracker.on('remove', update)
scope.$on('$destroy', function() {
tracker.removeListener('add', update)
tracker.removeListener('change', update)
tracker.removeListener('remove', update)
})
}
}
}