publish: omiv 0.3.0
* Store injection by render method * Add reset method to reset store
This commit is contained in:
parent
3a1ad7c759
commit
2b2e45f494
|
@ -9,20 +9,8 @@ import { $ } from 'omiv'
|
|||
import HelloWorld from './components/HelloWorld.vue'
|
||||
|
||||
export default $({
|
||||
name: 'app',
|
||||
components: {
|
||||
HelloWorld
|
||||
},
|
||||
store: new class {
|
||||
data = {
|
||||
count: 1
|
||||
};
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
};
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
@ -53,22 +41,32 @@ export default $({
|
|||
</script>
|
||||
```
|
||||
|
||||
Store injection:
|
||||
|
||||
```jsx
|
||||
import { render } from 'omiv'
|
||||
import App from 'App.vue'
|
||||
|
||||
const store = new class {
|
||||
data = {
|
||||
count: 1
|
||||
};
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
};
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
}
|
||||
|
||||
render(App, '#app', store)
|
||||
```
|
||||
|
||||
## Multi-store injection
|
||||
|
||||
Injecting multiple stores from the root node:
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div id="app">
|
||||
<img alt="Vue logo" src="./assets/logo.png">
|
||||
<HelloWorld msg="Welcome to Your Vue + Omiv App"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { $ } from './omiv/omiv'
|
||||
import HelloWorld from './components/HelloWorld.vue'
|
||||
Injecting multiple stores by `render` method:
|
||||
|
||||
```jsx
|
||||
const cs = new class {
|
||||
data = {
|
||||
count: 1
|
||||
|
@ -90,14 +88,26 @@ const ns = new class {
|
|||
}
|
||||
}
|
||||
|
||||
render(App, '#app', { cs, ns })
|
||||
```
|
||||
|
||||
App.vue:
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div id="app">
|
||||
<img alt="Vue logo" src="./assets/logo.png">
|
||||
<HelloWorld msg="Welcome to Your Vue + Omiv App"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { $ } from './omiv/omiv'
|
||||
import HelloWorld from './components/HelloWorld.vue'
|
||||
|
||||
export default $({
|
||||
name: 'app',
|
||||
components: {
|
||||
HelloWorld
|
||||
},
|
||||
store: {
|
||||
cs,
|
||||
ns
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
/**
|
||||
* omiv v0.2.0 http://omijs.org
|
||||
* omiv v0.3.0 http://omijs.org
|
||||
* 1kb store system for Vue apps.
|
||||
* By dntzhang https://github.com/dntzhang
|
||||
* Github: https://github.com/Tencent/omi
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
(function (Vue) {
|
||||
'use strict';
|
||||
|
||||
Vue = Vue && Vue.hasOwnProperty('default') ? Vue['default'] : Vue;
|
||||
|
||||
function obaa(target, arr, callback) {
|
||||
var eventPropArr = [];
|
||||
if (isArray(target)) {
|
||||
|
@ -253,20 +255,6 @@
|
|||
var useSelf = options.useSelf;
|
||||
options.computed = options.computed || {};
|
||||
|
||||
if (options.store) {
|
||||
store = options.store;
|
||||
if (store.data) {
|
||||
observe(store);
|
||||
} else {
|
||||
isMultiStore = true;
|
||||
for (var key in store) {
|
||||
if (store[key].data) {
|
||||
observe(store[key], key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
options.beforeCreate = function () {
|
||||
this.$store = store;
|
||||
if (isMultiStore) {
|
||||
|
@ -302,9 +290,9 @@
|
|||
|
||||
options.destroyed = function () {
|
||||
if (isMultiStore) {
|
||||
for (var _key in store) {
|
||||
removeItem(this, store[_key].components);
|
||||
removeItem(this, store[_key].updateSelfComponents);
|
||||
for (var key in store) {
|
||||
removeItem(this, store[key].components);
|
||||
removeItem(this, store[key].updateSelfComponents);
|
||||
}
|
||||
} else {
|
||||
removeItem(this, store.updateSelfComponents);
|
||||
|
@ -322,11 +310,11 @@
|
|||
});
|
||||
return state;
|
||||
}
|
||||
return this.$store.data;
|
||||
return store.data;
|
||||
};
|
||||
|
||||
options.computed.store = function () {
|
||||
return this.$store;
|
||||
return store;
|
||||
};
|
||||
|
||||
return options;
|
||||
|
@ -380,9 +368,35 @@
|
|||
}
|
||||
}
|
||||
|
||||
var Omiv = { $: $ };
|
||||
function render(app, renderTo, store, options) {
|
||||
reset(store);
|
||||
new Vue(Object.assign({
|
||||
render: function render(h) {
|
||||
return h(app);
|
||||
}
|
||||
}, options)).$mount(renderTo);
|
||||
}
|
||||
|
||||
function reset(s) {
|
||||
if (s) {
|
||||
store = s;
|
||||
if (store.data) {
|
||||
isMultiStore = false;
|
||||
observe(store);
|
||||
} else {
|
||||
isMultiStore = true;
|
||||
for (var key in store) {
|
||||
if (store[key].data) {
|
||||
observe(store[key], key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var Omiv = { $: $, render: render, reset: reset };
|
||||
|
||||
if (typeof module != 'undefined') module.exports = Omiv;else self.Omiv = Omiv;
|
||||
|
||||
}());
|
||||
}(Vue));
|
||||
//# sourceMappingURL=omiv.dev.js.map
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,11 +1,13 @@
|
|||
/**
|
||||
* omiv v0.2.0 http://omijs.org
|
||||
* omiv v0.3.0 http://omijs.org
|
||||
* 1kb store system for Vue apps.
|
||||
* By dntzhang https://github.com/dntzhang
|
||||
* Github: https://github.com/Tencent/omi
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
import Vue from 'vue';
|
||||
|
||||
function obaa(target, arr, callback) {
|
||||
var eventPropArr = [];
|
||||
if (isArray(target)) {
|
||||
|
@ -250,20 +252,6 @@ function $(options) {
|
|||
var useSelf = options.useSelf;
|
||||
options.computed = options.computed || {};
|
||||
|
||||
if (options.store) {
|
||||
store = options.store;
|
||||
if (store.data) {
|
||||
observe(store);
|
||||
} else {
|
||||
isMultiStore = true;
|
||||
for (var key in store) {
|
||||
if (store[key].data) {
|
||||
observe(store[key], key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
options.beforeCreate = function () {
|
||||
this.$store = store;
|
||||
if (isMultiStore) {
|
||||
|
@ -299,9 +287,9 @@ function $(options) {
|
|||
|
||||
options.destroyed = function () {
|
||||
if (isMultiStore) {
|
||||
for (var _key in store) {
|
||||
removeItem(this, store[_key].components);
|
||||
removeItem(this, store[_key].updateSelfComponents);
|
||||
for (var key in store) {
|
||||
removeItem(this, store[key].components);
|
||||
removeItem(this, store[key].updateSelfComponents);
|
||||
}
|
||||
} else {
|
||||
removeItem(this, store.updateSelfComponents);
|
||||
|
@ -319,11 +307,11 @@ function $(options) {
|
|||
});
|
||||
return state;
|
||||
}
|
||||
return this.$store.data;
|
||||
return store.data;
|
||||
};
|
||||
|
||||
options.computed.store = function () {
|
||||
return this.$store;
|
||||
return store;
|
||||
};
|
||||
|
||||
return options;
|
||||
|
@ -377,8 +365,34 @@ function removeItem(item, arr) {
|
|||
}
|
||||
}
|
||||
|
||||
var omiv = { $: $ };
|
||||
function render(app, renderTo, store, options) {
|
||||
reset(store);
|
||||
new Vue(Object.assign({
|
||||
render: function render(h) {
|
||||
return h(app);
|
||||
}
|
||||
}, options)).$mount(renderTo);
|
||||
}
|
||||
|
||||
function reset(s) {
|
||||
if (s) {
|
||||
store = s;
|
||||
if (store.data) {
|
||||
isMultiStore = false;
|
||||
observe(store);
|
||||
} else {
|
||||
isMultiStore = true;
|
||||
for (var key in store) {
|
||||
if (store[key].data) {
|
||||
observe(store[key], key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var omiv = { $: $, render: render, reset: reset };
|
||||
|
||||
export default omiv;
|
||||
export { $ };
|
||||
export { $, render, reset };
|
||||
//# sourceMappingURL=omiv.esm.js.map
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,4 @@
|
|||
!function() {
|
||||
!function(Vue) {
|
||||
'use strict';
|
||||
function obaa(target, arr, callback) {
|
||||
var eventPropArr = [];
|
||||
|
@ -134,13 +134,6 @@
|
|||
var use = options.use;
|
||||
var useSelf = options.useSelf;
|
||||
options.computed = options.computed || {};
|
||||
if (options.store) {
|
||||
store = options.store;
|
||||
if (store.data) observe(store); else {
|
||||
isMultiStore = !0;
|
||||
for (var key in store) if (store[key].data) observe(store[key], key);
|
||||
}
|
||||
}
|
||||
options.beforeCreate = function() {
|
||||
this.$store = store;
|
||||
if (isMultiStore) {
|
||||
|
@ -173,9 +166,9 @@
|
|||
beforeCreate && beforeCreate.apply(this, arguments);
|
||||
};
|
||||
options.destroyed = function() {
|
||||
if (isMultiStore) for (var _key in store) {
|
||||
removeItem(this, store[_key].components);
|
||||
removeItem(this, store[_key].updateSelfComponents);
|
||||
if (isMultiStore) for (var key in store) {
|
||||
removeItem(this, store[key].components);
|
||||
removeItem(this, store[key].updateSelfComponents);
|
||||
} else {
|
||||
removeItem(this, store.updateSelfComponents);
|
||||
removeItem(this, store.components);
|
||||
|
@ -190,10 +183,10 @@
|
|||
});
|
||||
return state;
|
||||
}
|
||||
return this.$store.data;
|
||||
return store.data;
|
||||
};
|
||||
options.computed.store = function() {
|
||||
return this.$store;
|
||||
return store;
|
||||
};
|
||||
return options;
|
||||
}
|
||||
|
@ -229,6 +222,27 @@
|
|||
break;
|
||||
}
|
||||
}
|
||||
function render(app, renderTo, store, options) {
|
||||
reset(store);
|
||||
new Vue(Object.assign({
|
||||
render: function(h) {
|
||||
return h(app);
|
||||
}
|
||||
}, options)).$mount(renderTo);
|
||||
}
|
||||
function reset(s) {
|
||||
if (s) {
|
||||
store = s;
|
||||
if (store.data) {
|
||||
isMultiStore = !1;
|
||||
observe(store);
|
||||
} else {
|
||||
isMultiStore = !0;
|
||||
for (var key in store) if (store[key].data) observe(store[key], key);
|
||||
}
|
||||
}
|
||||
}
|
||||
Vue = Vue && Vue.hasOwnProperty('default') ? Vue.default : Vue;
|
||||
var triggerStr = [ 'concat', 'copyWithin', 'fill', 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'size' ].join(',');
|
||||
var methods = [ 'concat', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values', 'size' ];
|
||||
obaa.add = function(obj, prop) {
|
||||
|
@ -244,8 +258,10 @@
|
|||
var store;
|
||||
var isMultiStore = !1;
|
||||
var Omiv = {
|
||||
$: $
|
||||
$: $,
|
||||
render: render,
|
||||
reset: reset
|
||||
};
|
||||
if ('undefined' != typeof module) module.exports = Omiv; else self.Omiv = Omiv;
|
||||
}();
|
||||
}(Vue);
|
||||
//# sourceMappingURL=omiv.js.map
|
File diff suppressed because one or more lines are too long
|
@ -1,2 +1,2 @@
|
|||
!function(){"use strict";function t(t,r,o){var i=[];s(t)&&(0===t.length&&(t.S={T:t,U:"#"}),e(t,t));for(var a in t)t.hasOwnProperty(a)&&(o?s(r)&&u(r,a)?(i.push(a),n(t,a,null,t)):f(r)&&a===r&&(i.push(a),n(t,a,null,t)):(i.push(a),n(t,a,null,t)));t.V||(t.V=[]),t.V.push({all:!o,propChanged:o||r,eventPropArr:i})}function e(t,e){g.forEach(function(i){t[i]=function(){var t=Array.prototype.slice.call(this,0),s=Array.prototype[i].apply(this,Array.prototype.slice.call(arguments));if(RegExp("\\b"+i+"\\b").test(m)){for(var f in this)this.hasOwnProperty(f)&&!o(this[f])&&n(this,f,this.S.U,e);r("Array-"+i,this,t,this,this.S.U,e)}return s},t["pure"+i.substring(0,1).toUpperCase()+i.substring(1)]=function(){return Array.prototype[i].apply(this,Array.prototype.slice.call(arguments))}})}function n(t,r,i,f){if("__o_"!==r&&!o(t[r])){t.S||(t.S={T:f}),t.S.U=void 0!==i&&null!==i?i:"#";var u=t.S[r]=t[r];if("object"==typeof u){s(u)&&(e(u,f),0===u.length&&(u.S||(u.S={}),u.S.U=void 0!==i&&null!==i?i+"-"+r:"#-"+r));for(var a in u)u.hasOwnProperty(a)&&n(u,a,t.S.U+"-"+r,f)}}}function r(t,e,r,o,s,f){if(e!==r&&(!i(e)||!i(r))&&f.V)for(var c=a(t,s),p=0,l=f.V.length;p<l;p++){var h=f.V[p];(h.all||u(h.eventPropArr,c)||0===c.indexOf("Array-"))&&h.propChanged.call(o,t,e,r,s)}0!==t.indexOf("Array-")&&"object"==typeof e&&n(o,t,o.S.U,f)}function o(t){return"[object Function]"===Object.prototype.toString.call(t)}function i(t){return"number"==typeof t&&isNaN(t)}function s(t){return"[object Array]"===Object.prototype.toString.call(t)}function f(t){return"string"==typeof t}function u(t,e){for(var n=t.length;--n>-1;)if(e===t[n])return!0;return!1}function a(t,e){return"#"===e?t:e.split("-")[1]}function c(t,e,n){var r={};return t.forEach(function(t){if("string"==typeof t)r[t]=!0;else{var e=t[Object.keys(t)[0]];"string"==typeof e?r[e]=!0:"string"==typeof e[0]?r[e[0]]=!0:e[0].forEach(function(t){return r[t]=!0})}}),e&&(e[n]=r),r}function p(t,e){for(var n in t){if(e[n])return!0;for(var r in e)if(l(n,r))return!0}return!1}function l(t,e){if(0===t.indexOf(e)){var n=t.substr(e.length,1);if("["===n||"."===n)return!0}return!1}function h(t){var e="";return t.replace("#-","").split("-").forEach(function(t,n){n?isNaN(+t)?e+="."+t:e+="["+t+"]":e+=t}),e}function d(t){var e=t.beforeCreate,n=t.destroyed,r=t.use,o=t.useSelf;if(t.computed=t.computed||{},t.store)if(b=t.store,b.data)v(b);else{O=!0;for(var i in b)b[i].data&&v(b[i],i)}return t.beforeCreate=function(){if(this.$store=b,O){if(r){var t={};for(var n in r)c(r[n],t,n),b[n].components.push(this);this.W=t}if(o){var i={};for(var s in o)c(o[s],i,s),b[s].updateSelfComponents.push(this);this.Y=i}}else r&&(this.W=c(r),b.components.push(this)),o&&(this.Y=c(o),b.updateSelfComponents.push(this));e&&e.apply(this,arguments)},t.destroyed=function(){if(O)for(var t in b)S(this,b[t].components),S(this,b[t].updateSelfComponents);else S(this,b.updateSelfComponents),S(this,b.components);n&&n.apply(this,arguments)},t.computed.state=function(){if(O){var t={};return Object.keys(b).forEach(function(e){t[e]=b[e].data}),t}return this.$store.data},t.computed.store=function(){return this.$store},t}function y(t){t.$forceUpdate(),t.$children.forEach(function(t){y(t)})}function v(e,n){e.components=[],e.updateSelfComponents=[],t(e.data,function(t,r,o,i){var s={};s[h(i+"-"+t)]=!0,e.components.forEach(function(t){var e=t.W;n?e&&e[n]&&p(s,e[n])&&y(t):e&&p(s,e)&&y(t)}),e.updateSelfComponents.forEach(function(t){var e=t.Y;n?e&&e[n]&&p(s,e[n])&&t.$forceUpdate():e&&p(s,e)&&t.$forceUpdate()})})}function S(t,e){for(var n=0,r=e.length;n<r;n++)if(e[n]===t){e.splice(n,1);break}}var m="concat,copyWithin,fill,pop,push,reverse,shift,sort,splice,unshift,size",g=["concat","copyWithin","entries","every","fill","filter","find","findIndex","forEach","includes","indexOf","join","keys","lastIndexOf","map","pop","push","reduce","reduceRight","reverse","shift","slice","some","sort","splice","toLocaleString","toString","unshift","values","size"];t.add=function(t,e){n(t,e,t.S.U,t.S.T)},t.set=function(t,e,r){n(t,e,t.S.U,t.S.T),t[e]=r},Array.prototype.size=function(t){this.length=t};var b,O=!1,U={$:d};"undefined"!=typeof module?module.exports=U:self.Omiv=U}();
|
||||
!function(t){"use strict";function n(t,n,o){var i=[];s(t)&&(0===t.length&&(t.S={T:t,U:"#"}),e(t,t));for(var f in t)t.hasOwnProperty(f)&&(o?s(n)&&a(n,f)?(i.push(f),r(t,f,null,t)):u(n)&&f===n&&(i.push(f),r(t,f,null,t)):(i.push(f),r(t,f,null,t)));t.V||(t.V=[]),t.V.push({all:!o,propChanged:o||n,eventPropArr:i})}function e(t,n){U.forEach(function(e){t[e]=function(){var t=Array.prototype.slice.call(this,0),f=Array.prototype[e].apply(this,Array.prototype.slice.call(arguments));if(RegExp("\\b"+e+"\\b").test(O)){for(var s in this)this.hasOwnProperty(s)&&!i(this[s])&&r(this,s,this.S.U,n);o("Array-"+e,this,t,this,this.S.U,n)}return f},t["pure"+e.substring(0,1).toUpperCase()+e.substring(1)]=function(){return Array.prototype[e].apply(this,Array.prototype.slice.call(arguments))}})}function r(t,n,o,f){if("__o_"!==n&&!i(t[n])){t.S||(t.S={T:f}),t.S.U=void 0!==o&&null!==o?o:"#";var u=t.S[n]=t[n];if("object"==typeof u){s(u)&&(e(u,f),0===u.length&&(u.S||(u.S={}),u.S.U=void 0!==o&&null!==o?o+"-"+n:"#-"+n));for(var a in u)u.hasOwnProperty(a)&&r(u,a,t.S.U+"-"+n,f)}}}function o(t,n,e,o,i,s){if(n!==e&&(!f(n)||!f(e))&&s.V)for(var u=c(t,i),p=0,l=s.V.length;p<l;p++){var h=s.V[p];(h.all||a(h.eventPropArr,u)||0===u.indexOf("Array-"))&&h.propChanged.call(o,t,n,e,i)}0!==t.indexOf("Array-")&&"object"==typeof n&&r(o,t,o.S.U,s)}function i(t){return"[object Function]"===Object.prototype.toString.call(t)}function f(t){return"number"==typeof t&&isNaN(t)}function s(t){return"[object Array]"===Object.prototype.toString.call(t)}function u(t){return"string"==typeof t}function a(t,n){for(var e=t.length;--e>-1;)if(n===t[e])return!0;return!1}function c(t,n){return"#"===n?t:n.split("-")[1]}function p(t,n,e){var r={};return t.forEach(function(t){if("string"==typeof t)r[t]=!0;else{var n=t[Object.keys(t)[0]];"string"==typeof n?r[n]=!0:"string"==typeof n[0]?r[n[0]]=!0:n[0].forEach(function(t){return r[t]=!0})}}),n&&(n[e]=r),r}function l(t,n){for(var e in t){if(n[e])return!0;for(var r in n)if(h(e,r))return!0}return!1}function h(t,n){if(0===t.indexOf(n)){var e=t.substr(n.length,1);if("["===e||"."===e)return!0}return!1}function d(t){var n="";return t.replace("#-","").split("-").forEach(function(t,e){e?isNaN(+t)?n+="."+t:n+="["+t+"]":n+=t}),n}function y(t){var n=t.beforeCreate,e=t.destroyed,r=t.use,o=t.useSelf;return t.computed=t.computed||{},t.beforeCreate=function(){if(this.$store=A,C){if(r){var t={};for(var e in r)p(r[e],t,e),A[e].components.push(this);this.W=t}if(o){var i={};for(var f in o)p(o[f],i,f),A[f].updateSelfComponents.push(this);this.Y=i}}else r&&(this.W=p(r),A.components.push(this)),o&&(this.Y=p(o),A.updateSelfComponents.push(this));n&&n.apply(this,arguments)},t.destroyed=function(){if(C)for(var t in A)m(this,A[t].components),m(this,A[t].updateSelfComponents);else m(this,A.updateSelfComponents),m(this,A.components);e&&e.apply(this,arguments)},t.computed.state=function(){if(C){var t={};return Object.keys(A).forEach(function(n){t[n]=A[n].data}),t}return A.data},t.computed.store=function(){return A},t}function v(t){t.$forceUpdate(),t.$children.forEach(function(t){v(t)})}function S(t,e){t.components=[],t.updateSelfComponents=[],n(t.data,function(n,r,o,i){var f={};f[d(i+"-"+n)]=!0,t.components.forEach(function(t){var n=t.W;e?n&&n[e]&&l(f,n[e])&&v(t):n&&l(f,n)&&v(t)}),t.updateSelfComponents.forEach(function(t){var n=t.Y;e?n&&n[e]&&l(f,n[e])&&t.$forceUpdate():n&&l(f,n)&&t.$forceUpdate()})})}function m(t,n){for(var e=0,r=n.length;e<r;e++)if(n[e]===t){n.splice(e,1);break}}function g(n,e,r,o){b(r),new t(Object.assign({render:function(t){return t(n)}},o)).$mount(e)}function b(t){if(t)if(A=t,A.data)C=!1,S(A);else{C=!0;for(var n in A)A[n].data&&S(A[n],n)}}t=t&&t.hasOwnProperty("default")?t.default:t;var O="concat,copyWithin,fill,pop,push,reverse,shift,sort,splice,unshift,size",U=["concat","copyWithin","entries","every","fill","filter","find","findIndex","forEach","includes","indexOf","join","keys","lastIndexOf","map","pop","push","reduce","reduceRight","reverse","shift","slice","some","sort","splice","toLocaleString","toString","unshift","values","size"];n.add=function(t,n){r(t,n,t.S.U,t.S.T)},n.set=function(t,n,e){r(t,n,t.S.U,t.S.T),t[n]=e},Array.prototype.size=function(t){this.length=t};var A,C=!1,j={$:y,render:g,reset:b};"undefined"!=typeof module?module.exports=j:self.Omiv=j}(Vue);
|
||||
//# sourceMappingURL=omiv.min.js.map
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "omiv",
|
||||
"version": "0.2.0",
|
||||
"version": "0.3.0",
|
||||
"description": "1kb store system for Vue apps.",
|
||||
"main": "dist/omiv.js",
|
||||
"jsnext:main": "dist/omiv.esm.js",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { $ } from './vue'
|
||||
import { $, render, reset } from './vue'
|
||||
|
||||
export default { $ }
|
||||
export default { $, render, reset }
|
||||
|
||||
export { $ }
|
||||
export { $, render, reset }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { obaa } from './obaa'
|
||||
import { getPath, needUpdate, fixPath } from './path'
|
||||
import Vue from 'vue'
|
||||
|
||||
let store
|
||||
let isMultiStore = false
|
||||
|
@ -11,21 +12,6 @@ export function $(options) {
|
|||
const useSelf = options.useSelf
|
||||
options.computed = options.computed || {}
|
||||
|
||||
if (options.store) {
|
||||
store = options.store
|
||||
if (store.data) {
|
||||
observe(store)
|
||||
} else {
|
||||
isMultiStore = true
|
||||
for (let key in store) {
|
||||
if (store[key].data) {
|
||||
observe(store[key], key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
options.beforeCreate = function () {
|
||||
this.$store = store
|
||||
if (isMultiStore) {
|
||||
|
@ -83,11 +69,11 @@ export function $(options) {
|
|||
})
|
||||
return state
|
||||
}
|
||||
return this.$store.data
|
||||
return store.data
|
||||
}
|
||||
|
||||
options.computed.store = function () {
|
||||
return this.$store
|
||||
return store
|
||||
}
|
||||
|
||||
return options
|
||||
|
@ -139,4 +125,29 @@ function removeItem(item, arr) {
|
|||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function render(app, renderTo, store, options) {
|
||||
reset(store)
|
||||
new Vue(Object.assign({
|
||||
render: h => h(app),
|
||||
}, options)).$mount(renderTo)
|
||||
|
||||
}
|
||||
|
||||
export function reset(s) {
|
||||
if (s) {
|
||||
store = s
|
||||
if (store.data) {
|
||||
isMultiStore = false
|
||||
observe(store)
|
||||
} else {
|
||||
isMultiStore = true
|
||||
for (let key in store) {
|
||||
if (store[key].data) {
|
||||
observe(store[key], key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
<script>
|
||||
import { $ } from '../../../src/omiv'
|
||||
|
||||
|
||||
console.log(111111111111)
|
||||
export default $({
|
||||
use: ['count']
|
||||
})
|
||||
|
|
|
@ -6,22 +6,10 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { $ } from '../../../src/omiv'
|
||||
import { $ } from '../../../src/omiv'
|
||||
|
||||
const cs = new class {
|
||||
data = {
|
||||
count: 2
|
||||
}
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
}
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
}
|
||||
|
||||
export default $({
|
||||
store: cs,
|
||||
use: ['count']
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -6,31 +6,9 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { $ } from '../../../src/omiv'
|
||||
|
||||
const cs = new class {
|
||||
data = {
|
||||
count: 2
|
||||
}
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
}
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
}
|
||||
|
||||
const rs = new class {
|
||||
data = {
|
||||
name: 'omiv'
|
||||
}
|
||||
rename = () => {
|
||||
this.data.name = 'omiv + vue'
|
||||
}
|
||||
}
|
||||
import { $ } from '../../../src/omiv'
|
||||
|
||||
export default $({
|
||||
store: { cs, rs },
|
||||
use: {
|
||||
cs: ['count']
|
||||
}
|
||||
|
|
|
@ -8,21 +8,8 @@
|
|||
|
||||
import Child from './child.vue'
|
||||
import { $ } from '../../../src/omiv'
|
||||
console.log(22222222222222)
|
||||
const cs = new class {
|
||||
data = {
|
||||
count: 2
|
||||
}
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
}
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
}
|
||||
|
||||
export default $({
|
||||
store: cs,
|
||||
components: {
|
||||
Child
|
||||
}
|
||||
|
|
|
@ -6,21 +6,10 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { $ } from '../../../src/omiv'
|
||||
import { $ } from '../../../src/omiv'
|
||||
|
||||
const cs = new class {
|
||||
data = {
|
||||
count: 2
|
||||
}
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
}
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
}
|
||||
|
||||
export default $({
|
||||
store: cs
|
||||
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -2,6 +2,7 @@ import Counter from './components/counter.vue'
|
|||
import Simple from './components/simple.vue'
|
||||
import Event from './components/event.vue'
|
||||
import Vue from 'vue'
|
||||
import { render } from '../../src/omiv'
|
||||
//import Nest from './components/nest.vue'
|
||||
|
||||
const errorHandler = (error, vm) => {
|
||||
|
@ -47,9 +48,18 @@ describe('base', () => {
|
|||
|
||||
it('simple test', () => {
|
||||
|
||||
new Vue({
|
||||
render: h => h(Simple)
|
||||
}).$mount('#app')
|
||||
|
||||
render(Simple, '#app', new class {
|
||||
data = {
|
||||
count: 2
|
||||
}
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
}
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
})
|
||||
|
||||
expect(document.querySelector('#app').innerHTML).to.equal('<span class="count">2</span> <button>Increment</button>')
|
||||
|
||||
|
@ -58,25 +68,54 @@ describe('base', () => {
|
|||
|
||||
it('simple event test', (done) => {
|
||||
|
||||
new Vue({
|
||||
render: h => h(Event)
|
||||
}).$mount('#app')
|
||||
render(Event, '#app', new class {
|
||||
data = {
|
||||
count: 4
|
||||
}
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
}
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
document.querySelector('#btn').click()
|
||||
|
||||
Vue.nextTick(() => {
|
||||
done()
|
||||
expect(document.querySelector('#app').innerHTML)
|
||||
.to.equal('<span class="count">3</span> <button id="btn">Increment</button>')
|
||||
.to.equal('<span class="count">5</span> <button id="btn">Increment</button>')
|
||||
})
|
||||
})
|
||||
|
||||
it('multi-store test', (done) => {
|
||||
|
||||
new Vue({
|
||||
render: h => h(require('./components/multi-store.vue')
|
||||
.default)
|
||||
}).$mount('#app')
|
||||
const cs = new class {
|
||||
data = {
|
||||
count: 2
|
||||
}
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
}
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
}
|
||||
|
||||
const rs = new class {
|
||||
data = {
|
||||
name: 'omiv'
|
||||
}
|
||||
rename = () => {
|
||||
this.data.name = 'omiv + vue'
|
||||
}
|
||||
}
|
||||
|
||||
render(require('./components/multi-store.vue')
|
||||
.default, '#app', {cs,rs})
|
||||
|
||||
|
||||
document.querySelector('#btn').click()
|
||||
|
||||
|
@ -87,21 +126,30 @@ describe('base', () => {
|
|||
})
|
||||
})
|
||||
|
||||
// it('nest test', (done) => {
|
||||
// reset()
|
||||
// new Vue({
|
||||
// render: h => h(require('./components/nest.vue')
|
||||
// .default)
|
||||
// }).$mount('#app')
|
||||
it('nest test', (done) => {
|
||||
|
||||
// //document.querySelector('#btn').click()
|
||||
const cs = new class {
|
||||
data = {
|
||||
count: 2
|
||||
}
|
||||
sub = () => {
|
||||
this.data.count--
|
||||
}
|
||||
add = () => {
|
||||
this.data.count++
|
||||
}
|
||||
}
|
||||
render(require('./components/nest.vue')
|
||||
.default, '#app', cs)
|
||||
|
||||
// Vue.nextTick(() => {
|
||||
// done()
|
||||
// expect(document.querySelector('#app').innerHTML)
|
||||
// .to.equal('<span class="count">1</span> <button id="btn">sub</button>')
|
||||
// })
|
||||
// })
|
||||
document.querySelector('button').click()
|
||||
|
||||
Vue.nextTick(() => {
|
||||
done()
|
||||
expect(document.querySelector('#app').innerHTML)
|
||||
.to.equal('<div><span class="count">3</span> <button>Increment</button></div>')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue