Skip to content

Commit 2d308c7

Browse files
committed
Added statics
1 parent 569698c commit 2d308c7

File tree

3 files changed

+270
-135
lines changed

3 files changed

+270
-135
lines changed

dist/vue-sap.cjs.js

Lines changed: 90 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,97 @@
11
'use strict';
22

3+
function createStore(Vue) {
4+
var store = new Vue({ data: { subscriptions: {}, statics: {} } });
5+
Vue.prototype.$subscriptions = store.subscriptions;
6+
Vue.prototype.$statics = store.statics;
7+
}
8+
9+
function hasProp(obj, prop) {
10+
if (obj.hasOwnProperty) {
11+
return obj.hasOwnProperty(prop);
12+
} else {
13+
return !!obj[prop];
14+
}
15+
}
16+
17+
function definePublishedProperty(vm, key, obj) {
18+
var ss = vm.$subscriptions;
19+
vm.$set(ss, key, obj[key]);
20+
Object.defineProperty(vm, key, {
21+
get: function get() {
22+
return ss[key];
23+
},
24+
set: function set(newValue) {
25+
vm.$set(ss, key, newValue);
26+
}
27+
});
28+
}
29+
30+
function defineSubscribedProperty(vm, key, obj) {
31+
var ss = vm.$subscriptions;
32+
Object.defineProperty(vm, key, {
33+
get: function get() {
34+
return ss[key];
35+
},
36+
set: function set(newValue) {
37+
vm.$set(ss, key, newValue);
38+
}
39+
});
40+
}
41+
42+
function defineStaticProperty(vm, key, obj) {
43+
var ss = vm.$statics;
44+
var cid = vm.constructor.cid;
45+
if (!ss[cid]) {
46+
vm.$set(ss, cid, {});
47+
}
48+
if (!hasProp(ss[cid], key)) {
49+
vm.$set(ss[cid], key, obj[key]);
50+
}
51+
Object.defineProperty(vm, key, {
52+
get: function get() {
53+
return ss[cid][key];
54+
},
55+
set: function set(newValue) {
56+
vm.$set(ss[cid], key, newValue);
57+
}
58+
});
59+
}
60+
61+
var mixin = {
62+
created: function created() {
63+
var _$options = this.$options,
64+
published = _$options.published,
65+
subscribed = _$options.subscribed,
66+
statics = _$options.statics;
67+
68+
if (published) {
69+
for (var key in published) {
70+
definePublishedProperty(this, key, published);
71+
}
72+
}
73+
74+
if (subscribed) {
75+
for (var _key in subscribed) {
76+
defineSubscribedProperty(this, _key, subscribed);
77+
}
78+
this.$forceUpdate();
79+
}
80+
81+
if (statics) {
82+
for (var _key2 in statics) {
83+
defineStaticProperty(this, _key2, statics);
84+
}
85+
this.$forceUpdate();
86+
}
87+
}
88+
};
89+
90+
var subscriptions = createStore(Vue);
91+
392
var plugin = {
493
install: function install(Vue) {
5-
var ss = Vue.prototype.$Subscriptions = new Vue({ data: { subscriptions: {} } }).subscriptions;
6-
7-
Vue.mixin({
8-
created: function created() {
9-
var _this = this;
10-
11-
var p = this.$options.published;
12-
if (p) {
13-
var _loop = function _loop(key) {
14-
Vue.set(ss, key, p[key]);
15-
Object.defineProperty(_this, key, {
16-
get: function get() {
17-
return ss[key];
18-
},
19-
set: function set(newValue) {
20-
Vue.set(ss, key, newValue);
21-
}
22-
});
23-
};
24-
25-
for (var key in p) {
26-
_loop(key);
27-
}
28-
}
29-
var s = this.$options.subscribed;
30-
if (s) {
31-
var _loop2 = function _loop2(key) {
32-
33-
Object.defineProperty(_this, key, {
34-
get: function get() {
35-
return ss[key] || '';
36-
},
37-
set: function set(newValue) {
38-
Vue.set(ss, key, newValue);
39-
}
40-
});
41-
};
42-
43-
for (var key in s) {
44-
_loop2(key);
45-
}
46-
this.$forceUpdate();
47-
}
48-
}
49-
});
94+
Vue.mixin(mixin);
5095
}
5196
};
5297

dist/vue-sap.esm.js

Lines changed: 90 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,95 @@
1+
function createStore(Vue) {
2+
var store = new Vue({ data: { subscriptions: {}, statics: {} } });
3+
Vue.prototype.$subscriptions = store.subscriptions;
4+
Vue.prototype.$statics = store.statics;
5+
}
6+
7+
function hasProp(obj, prop) {
8+
if (obj.hasOwnProperty) {
9+
return obj.hasOwnProperty(prop);
10+
} else {
11+
return !!obj[prop];
12+
}
13+
}
14+
15+
function definePublishedProperty(vm, key, obj) {
16+
var ss = vm.$subscriptions;
17+
vm.$set(ss, key, obj[key]);
18+
Object.defineProperty(vm, key, {
19+
get: function get() {
20+
return ss[key];
21+
},
22+
set: function set(newValue) {
23+
vm.$set(ss, key, newValue);
24+
}
25+
});
26+
}
27+
28+
function defineSubscribedProperty(vm, key, obj) {
29+
var ss = vm.$subscriptions;
30+
Object.defineProperty(vm, key, {
31+
get: function get() {
32+
return ss[key];
33+
},
34+
set: function set(newValue) {
35+
vm.$set(ss, key, newValue);
36+
}
37+
});
38+
}
39+
40+
function defineStaticProperty(vm, key, obj) {
41+
var ss = vm.$statics;
42+
var cid = vm.constructor.cid;
43+
if (!ss[cid]) {
44+
vm.$set(ss, cid, {});
45+
}
46+
if (!hasProp(ss[cid], key)) {
47+
vm.$set(ss[cid], key, obj[key]);
48+
}
49+
Object.defineProperty(vm, key, {
50+
get: function get() {
51+
return ss[cid][key];
52+
},
53+
set: function set(newValue) {
54+
vm.$set(ss[cid], key, newValue);
55+
}
56+
});
57+
}
58+
59+
var mixin = {
60+
created: function created() {
61+
var _$options = this.$options,
62+
published = _$options.published,
63+
subscribed = _$options.subscribed,
64+
statics = _$options.statics;
65+
66+
if (published) {
67+
for (var key in published) {
68+
definePublishedProperty(this, key, published);
69+
}
70+
}
71+
72+
if (subscribed) {
73+
for (var _key in subscribed) {
74+
defineSubscribedProperty(this, _key, subscribed);
75+
}
76+
this.$forceUpdate();
77+
}
78+
79+
if (statics) {
80+
for (var _key2 in statics) {
81+
defineStaticProperty(this, _key2, statics);
82+
}
83+
this.$forceUpdate();
84+
}
85+
}
86+
};
87+
88+
var subscriptions = createStore(Vue);
89+
190
var plugin = {
291
install: function install(Vue) {
3-
var ss = Vue.prototype.$Subscriptions = new Vue({ data: { subscriptions: {} } }).subscriptions;
4-
5-
Vue.mixin({
6-
created: function created() {
7-
var _this = this;
8-
9-
var p = this.$options.published;
10-
if (p) {
11-
var _loop = function _loop(key) {
12-
Vue.set(ss, key, p[key]);
13-
Object.defineProperty(_this, key, {
14-
get: function get() {
15-
return ss[key];
16-
},
17-
set: function set(newValue) {
18-
Vue.set(ss, key, newValue);
19-
}
20-
});
21-
};
22-
23-
for (var key in p) {
24-
_loop(key);
25-
}
26-
}
27-
var s = this.$options.subscribed;
28-
if (s) {
29-
var _loop2 = function _loop2(key) {
30-
31-
Object.defineProperty(_this, key, {
32-
get: function get() {
33-
return ss[key] || '';
34-
},
35-
set: function set(newValue) {
36-
Vue.set(ss, key, newValue);
37-
}
38-
});
39-
};
40-
41-
for (var key in s) {
42-
_loop2(key);
43-
}
44-
this.$forceUpdate();
45-
}
46-
}
47-
});
92+
Vue.mixin(mixin);
4893
}
4994
};
5095

0 commit comments

Comments
 (0)