-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlainViewModel-umd.js
54 lines (46 loc) · 1.51 KB
/
PlainViewModel-umd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['knockout'], factory);
} else {
// Browser globals
root.PlainViewModel = factory(root.ko);
}
}(typeof self !== 'undefined' ? self : this, function (ko) {
var ViewModel = function() {
var self = this;
//#region Public Observables
self.isVisible = ko.observable(false);
self.status = ko.pureComputed(function() {
return self.isVisible() ? 'visible' : 'hidden';
});
//#endregion
//#region Private variables
var internalValue = 42;
//#endregion
//#region Public functions
self.setVisible = function(visible) {
self.isVisible(visible);
};
//#endregion
//#region Private functions
var strLength = function (str) {
return str.length;
};
//#endregion
//#region Subscriptions
self.isVisibleSubscription = self.isVisible.subscribe(function(newValue) {
internalValue = newValue ? 12 : 42;
});
//#endregion
//#region Disposal
self.dispose = function() {
self.isVisibleSubscription.dispose();
};
//#endregion
//#region Initialisation
self.isVisible(internalValue === strLength('start'));
//#endregion
}
return ViewModel;
}));