├── .babelrc ├── .travis.yml ├── .npmignore ├── examples ├── components │ ├── todo │ │ ├── index.less │ │ └── index.vue │ ├── counter │ │ └── index.vue │ └── repos │ │ └── index.vue ├── modules │ ├── index.js │ ├── counter.js │ ├── todo.js │ └── repos.js ├── dev-server.js ├── index.html ├── page │ ├── app.vue │ └── index.js └── webpack.config.js ├── bower.json ├── src ├── index.js ├── utils.js ├── install.js ├── helpers.js └── modules.js ├── .gitignore ├── .eslintrc ├── rollup.config.js ├── LICENSE ├── package.json ├── test ├── helper.js └── modules.js ├── README.md └── dist └── index.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-2"], 3 | "plugins": ["transform-runtime"] 4 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | branches: 4 | only: 5 | - master 6 | node_js: 7 | - '6' 8 | script: 9 | - npm test -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | .gitignore 3 | .vscode 4 | .npmrc 5 | .babelrc 6 | *.js 7 | node_modules 8 | bower.json 9 | karma-test 10 | ava-test -------------------------------------------------------------------------------- /examples/components/todo/index.less: -------------------------------------------------------------------------------- 1 | .list{ 2 | margin-left: 20px; 3 | li{ 4 | margin-top: 10px; 5 | cursor: pointer 6 | } 7 | } -------------------------------------------------------------------------------- /examples/modules/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Revuejs, { Modules } from 'revuejs'; 3 | 4 | import counter from './counter'; 5 | import todo from './todo'; 6 | import repos from './repos'; 7 | 8 | Vue.use(Revuejs); 9 | 10 | export default new Modules({ 11 | counter, 12 | todo, 13 | repos 14 | }); 15 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "revuejs", 3 | "main": "dist/index.js", 4 | "description": "A tiny, light and handy state management for vuejs 2.", 5 | "authors": ["pomysky@gmail.com"], 6 | "license": "MIT", 7 | "ignore": [ 8 | "*", 9 | "!dist", 10 | "!LICENSE", 11 | "!README.md" 12 | ] 13 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import install from './install'; 2 | 3 | export { mergeActions, mergeProps } from './helpers'; 4 | export { Modules } from './modules'; 5 | 6 | const Revuejs = { 7 | install 8 | }; 9 | 10 | export default Revuejs; 11 | 12 | // auto install 13 | if (typeof window !== 'undefined' && window.Vue) { 14 | window.Vue.use(Revuejs); 15 | }; 16 | -------------------------------------------------------------------------------- /examples/dev-server.js: -------------------------------------------------------------------------------- 1 | let webpack = require('webpack'); 2 | let WebpackDevServer = require('webpack-dev-server'); 3 | 4 | let webpackDevConfig = require('./webpack.config.js'); 5 | 6 | let compiler = webpack(webpackDevConfig); 7 | let server = new WebpackDevServer(compiler, webpackDevConfig.devServer); 8 | 9 | server.listen(8000, 'localhost', (err) => { 10 | if (err) { 11 | console.log('err', err.message); 12 | } 13 | }); 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build and Release Folders 2 | bin/ 3 | bin-debug/ 4 | bin-release/ 5 | [Oo]bj/ # FlashDevelop obj 6 | [Bb]in/ # FlashDevelop bin 7 | 8 | # Other files and folders 9 | .settings/ 10 | 11 | # Executables 12 | *.swf 13 | *.air 14 | *.ipa 15 | *.apk 16 | 17 | node_modules 18 | .idea 19 | 20 | # Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` 21 | # should NOT be excluded as they contain compiler settings and other important 22 | # information for Eclipse / Flash Builder. 23 | -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Examples for Revuejs 10 | 11 | 12 |
13 | 14 | -------------------------------------------------------------------------------- /examples/modules/counter.js: -------------------------------------------------------------------------------- 1 | export default { 2 | namespace: 'counter', 3 | state: { 4 | count: 0, 5 | title: 'Counter' 6 | }, 7 | actions: { 8 | increase (state, payload) { 9 | let newCount = state.count + 1; 10 | return Object.assign({}, state, { 11 | count: newCount 12 | }); 13 | }, 14 | decrease (state, payload) { 15 | let newCount = state.count - 1; 16 | return { 17 | count: newCount 18 | }; 19 | } 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /examples/modules/todo.js: -------------------------------------------------------------------------------- 1 | export default { 2 | namespace: 'todo', 3 | state: { 4 | list: [], 5 | total: 0, 6 | title: 'ToDo' 7 | }, 8 | actions: { 9 | addTodo (state, payload) { 10 | state.list.push(payload.item); 11 | return { 12 | list: state.list, 13 | total: state.list.length 14 | }; 15 | }, 16 | deleteTodo (state, payload) { 17 | state.list.splice(payload.index, 1); 18 | return { 19 | list: state.list, 20 | total: state.list.length 21 | }; 22 | } 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /examples/modules/repos.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import awaitTo from 'async-await-error-handling'; 3 | 4 | export default { 5 | namespace: 'repos', 6 | state: { 7 | all: 0, 8 | error: '', 9 | title: 'Repos' 10 | }, 11 | actions: { 12 | async getYourRepos (state, payload) { 13 | let {username} = payload; 14 | 15 | const [err, data] = await awaitTo(axios.get(`https://api.github.com/users/${username}/repos`)); 16 | 17 | return { 18 | all: data.data ? data.data.length : 0, 19 | error: !err ? '' : err 20 | }; 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true 4 | }, 5 | "extends": "standard", 6 | "rules": { 7 | "indent": [2, 4, { "SwitchCase": 1 }], 8 | "quotes": [2, "single", { "allowTemplateLiterals": true }], 9 | "linebreak-style": [2, "unix"], 10 | "semi": [2, "always"], 11 | "eqeqeq": [2, "always"], 12 | "strict": [2, "global"], 13 | "key-spacing": [2, { "afterColon": true }], 14 | "no-console": 0, 15 | "no-debugger": 0, 16 | "no-empty": 0, 17 | "no-unused-vars": 0, 18 | "no-constant-condition": 0, 19 | "no-undef": 0, 20 | "no-trailing-spaces": 0 21 | } 22 | } -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | export const SEP = '.'; 2 | 3 | export const isPromise = (val) => { 4 | return val && typeof val.then === 'function'; 5 | }; 6 | 7 | export const assert = (condition, msg = '') => { 8 | if (!condition) { 9 | throw new Error(`[revuejs]: ${msg}`); 10 | } 11 | }; 12 | 13 | export const isObject = (obj) => { 14 | return obj !== null && typeof obj === 'object'; 15 | }; 16 | 17 | export const normalizeMap = (map) => { 18 | return Array.isArray(map) 19 | ? map.map(key => ({ key, val: key })) 20 | : Object.keys(map).map(key => ({ key, val: map[key] })); 21 | }; 22 | 23 | export const hasOwn = (target, prop) => { 24 | return {}.hasOwnProperty.call(target, prop); 25 | }; 26 | -------------------------------------------------------------------------------- /src/install.js: -------------------------------------------------------------------------------- 1 | import { assert } from './utils'; 2 | 3 | export let _Vue; 4 | 5 | export default function install (Vue) { 6 | const version = Number(Vue.version.split('.')[0]); 7 | assert(version >= 2, `Only supports Vuejs 2 or higher`); 8 | 9 | if (install.installed) { 10 | return; 11 | } 12 | install.installed = true; 13 | 14 | _Vue = Vue; 15 | 16 | Vue.mixin({ 17 | beforeCreate () { 18 | const options = this.$options; 19 | if (options.modules) { 20 | this.$modules = options.modules; 21 | } else if (options.parent && options.parent.$modules) { 22 | this.$modules = options.parent.$modules; 23 | } 24 | } 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /examples/page/app.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 31 | 32 | 39 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import babel from 'rollup-plugin-babel'; 2 | import cleanup from 'rollup-plugin-cleanup'; 3 | import resolve from 'rollup-plugin-node-resolve'; 4 | import commonjs from 'rollup-plugin-commonjs'; 5 | 6 | export default { 7 | entry: 'src/index.js', 8 | format: 'umd', 9 | moduleName: 'Revuejs', 10 | dest: 'dist/index.js', 11 | plugins: [ 12 | resolve({ 13 | customResolveOptions: 'node_modules', 14 | jsnext: true, 15 | main: true 16 | }), 17 | commonjs({ 18 | namedExports: { 19 | 20 | } 21 | }), 22 | babel({ 23 | exclude: 'node_modules/**', 24 | externalHelpers: false, 25 | babelrc: false, 26 | runtimeHelpers: true, 27 | presets: [ 28 | [ 29 | 'es2015', 30 | { 31 | 'modules': false 32 | } 33 | ] 34 | ], 35 | plugins: ['transform-runtime'] 36 | }), 37 | cleanup() 38 | ] 39 | }; 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Pomy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/page/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import VueRouter from 'vue-router'; 3 | 4 | Vue.use(VueRouter); 5 | 6 | import modules from '../modules/index'; 7 | 8 | const App = () => import(/* webpackChunkName: "app" */ './app'); 9 | const Counter = () => import(/* webpackChunkName: "counter" */ '../components/counter/index'); 10 | const ToDo = () => import(/* webpackChunkName: "todo" */ '../components/todo/index'); 11 | const Repos = () => import(/* webpackChunkName: "repos" */ '../components/repos/index'); 12 | 13 | const Outer = { template: '' }; 14 | 15 | const router = new VueRouter({ 16 | mode: 'history', 17 | routes: [ 18 | { 19 | path: '/', 20 | component: Outer, 21 | children: [ 22 | { path: '', component: App }, 23 | { path: 'counter', component: Counter }, 24 | { path: 'todo', component: ToDo }, 25 | { path: 'repos', component: Repos } 26 | ] 27 | } 28 | ] 29 | }); 30 | 31 | const app = new Vue({ 32 | router, 33 | modules, 34 | ...Outer 35 | }); 36 | 37 | app.$mount('#app'); 38 | -------------------------------------------------------------------------------- /examples/components/counter/index.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 39 | 40 | -------------------------------------------------------------------------------- /examples/components/todo/index.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | -------------------------------------------------------------------------------- /src/helpers.js: -------------------------------------------------------------------------------- 1 | import { SEP, normalizeMap, assert, isObject } from './utils'; 2 | import { _root } from './modules'; 3 | 4 | export const mergeActions = (actions) => { 5 | const _validActions = Object.keys(_root._namespaceActions); 6 | let actionsVals; 7 | let res = {}; 8 | 9 | if (Array.isArray(actions)) { 10 | actionsVals = actions; 11 | } else { 12 | assert(isObject(actions), 'the parameter of mergeActions must be a array or plain object'); 13 | actionsVals = Object.values(actions); 14 | } 15 | 16 | // empty parameter 17 | if (!actionsVals.length) { 18 | return res; 19 | } 20 | 21 | // decide all action is valid 22 | actionsVals.forEach((action) => { 23 | assert(_validActions.includes(action), `the ${action} action is invalid`); 24 | }); 25 | 26 | normalizeMap(actions).forEach(({ key, val }) => { 27 | const k = key.indexOf(SEP) > -1 ? key.split(SEP)[1] : key; 28 | res[k] = function mappedAction (...args) { 29 | return _root._namespaceActions[val].apply(_root, [].concat(args)); 30 | }; 31 | }); 32 | 33 | return res; 34 | }; 35 | 36 | export const mergeProps = (props) => { 37 | const _validProps = Object.keys(_root._namespaceStates); 38 | let propsVals; 39 | let res = {}; 40 | 41 | if (Array.isArray(props)) { 42 | propsVals = props; 43 | } else { 44 | assert(isObject(props), 'the parameter of mergeProps must be a array or plain object'); 45 | propsVals = Object.values(props); 46 | } 47 | 48 | // empty parameter 49 | if (!propsVals.length) { 50 | return res; 51 | } 52 | 53 | // decide all prop is valid 54 | propsVals.forEach((prop) => { 55 | assert(_validProps.includes(prop), `the ${prop} prop is invalid`); 56 | }); 57 | 58 | normalizeMap(props).forEach(({ key, val }) => { 59 | const k = key.indexOf(SEP) > -1 ? key.split(SEP)[1] : key; 60 | res[k] = function mappedProps () { 61 | return _root.getters[val](); 62 | }; 63 | }); 64 | 65 | return res; 66 | }; 67 | -------------------------------------------------------------------------------- /examples/components/repos/index.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 58 | 59 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "revuejs", 3 | "version": "1.0.1", 4 | "description": "A tiny, light and handy state management for vuejs 2", 5 | "author": "pomysky@gmail.com", 6 | "main": "dist/index.js", 7 | "license": "MIT", 8 | "private": false, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/dwqs/revuejs" 12 | }, 13 | "keywords": [ 14 | "vue", 15 | "vuejs2", 16 | "modules", 17 | "state-management" 18 | ], 19 | "scripts": { 20 | "test": "./node_modules/.bin/ava ./test/**/*.js", 21 | "dev": "node ./examples/dev-server.js", 22 | "prepush": "npm run ilint -q", 23 | "prepublishOnly": "npm run build", 24 | "build": "npx rollup -c", 25 | "ilint": "npx eslint src/**/*.js", 26 | "fix": "npx eslint --fix src/**/*.js" 27 | }, 28 | "dependencies": {}, 29 | "devDependencies": { 30 | "async-await-error-handling": "^0.5.2", 31 | "ava": "^0.22.0", 32 | "axios": "^0.16.2", 33 | "babel-core": "^6.25.0", 34 | "babel-loader": "^7.1.1", 35 | "babel-plugin-transform-class-properties": "^6.24.1", 36 | "babel-plugin-transform-runtime": "^6.23.0", 37 | "babel-preset-es2015": "^6.24.1", 38 | "babel-preset-stage-2": "^6.24.1", 39 | "cross-env": "^5.0.1", 40 | "css-loader": "^0.28.4", 41 | "eslint": "^4.3.0", 42 | "eslint-config-standard": "^10.2.1", 43 | "eslint-plugin-import": "^2.7.0", 44 | "eslint-plugin-node": "^5.1.1", 45 | "eslint-plugin-promise": "^3.5.0", 46 | "eslint-plugin-standard": "^3.0.1", 47 | "html-webpack-plugin": "^2.29.0", 48 | "husky": "^0.14.2", 49 | "less": "^2.7.2", 50 | "less-loader": "^4.0.4", 51 | "open-browser-webpack-plugin": "^0.0.5", 52 | "rollup": "^0.45.2", 53 | "rollup-plugin-babel": "^2.7.1", 54 | "rollup-plugin-cleanup": "^1.0.1", 55 | "rollup-plugin-commonjs": "^8.2.0", 56 | "rollup-plugin-node-resolve": "^3.0.0", 57 | "vue": "^2.4.2", 58 | "vue-loader": "^13.0.0", 59 | "vue-router": "^2.7.0", 60 | "vue-style-loader": "^1.0.0", 61 | "vue-template-compiler": "^2.3.4", 62 | "webpack": "^3.0.0", 63 | "webpack-dev-server": "^2.5.0" 64 | }, 65 | "homepage": "https://github.com/dwqs/revuejs", 66 | "bugs": { 67 | "url": "https://github.com/dwqs/revuejs/issues" 68 | }, 69 | "engines": { 70 | "node": ">= 6.0.0", 71 | "npm": ">= 5.2.0" 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /test/helper.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import Vue from 'vue'; 3 | import Revuejs, { Modules, mergeActions, mergeProps } from '../dist/index'; 4 | 5 | let counter; 6 | let modules; 7 | 8 | test.beforeEach(t => { 9 | Vue.use(Revuejs); 10 | counter = { 11 | namespace: 'counter', 12 | state: { 13 | count: 0, 14 | title: 'test count' 15 | }, 16 | actions: { 17 | increase (state, payload) { 18 | let newCount = state.count + 1; 19 | return Object.assign({}, state, { 20 | count: newCount 21 | }); 22 | }, 23 | decrease (state, payload) { 24 | let newCount = state.count - 1; 25 | return { 26 | count: newCount 27 | }; 28 | } 29 | } 30 | }; 31 | modules = new Modules({ 32 | counter 33 | }); 34 | }); 35 | 36 | test('mergeProps(Array)', (t) => { 37 | t.plan(2); 38 | const vm = new Vue({ 39 | modules, 40 | computed: mergeProps(['counter.count', 'counter.title']) 41 | }); 42 | t.is(vm.count, counter.state.count); 43 | t.is(vm.title, counter.state.title); 44 | }); 45 | 46 | test('mergeProps(Object)', (t) => { 47 | t.plan(2); 48 | const vm = new Vue({ 49 | modules, 50 | computed: mergeProps({ 51 | ct: 'counter.count', 52 | tl: 'counter.title' 53 | }) 54 | }); 55 | t.is(vm.ct, counter.state.count); 56 | t.is(vm.tl, counter.state.title); 57 | }); 58 | 59 | test('mergeActions(Array)', (t) => { 60 | t.plan(5); 61 | const vm = new Vue({ 62 | modules, 63 | computed: mergeProps(['counter.count']), 64 | methods: mergeActions(['counter.increase', 'counter.decrease']) 65 | }); 66 | 67 | t.is(vm.count, 0); 68 | t.is(typeof vm.increase, 'function'); 69 | t.is(typeof vm.decrease, 'function'); 70 | 71 | vm.increase(); 72 | 73 | t.is(vm.count, counter.state.count); 74 | 75 | vm.decrease(); 76 | vm.decrease(); 77 | 78 | t.is(vm.count, counter.state.count); 79 | }); 80 | 81 | test('mergeActions(Object)', (t) => { 82 | t.plan(5); 83 | const vm = new Vue({ 84 | modules, 85 | computed: mergeProps(['counter.count']), 86 | methods: mergeActions({ 87 | inc: 'counter.increase', 88 | dec: 'counter.decrease' 89 | }) 90 | }); 91 | 92 | t.is(vm.count, 0); 93 | t.is(typeof vm.inc, 'function'); 94 | t.is(typeof vm.dec, 'function'); 95 | 96 | vm.inc(); 97 | 98 | t.is(vm.count, counter.state.count); 99 | 100 | vm.dec(); 101 | vm.dec(); 102 | 103 | t.is(vm.count, counter.state.count); 104 | }); 105 | -------------------------------------------------------------------------------- /examples/webpack.config.js: -------------------------------------------------------------------------------- 1 | let path = require('path'); 2 | let webpack = require('webpack'); 3 | let HtmlWebpackPlugin = require('html-webpack-plugin'); 4 | let OpenBrowserPlugin = require('open-browser-webpack-plugin'); 5 | 6 | const url = 'http://localhost:8000'; 7 | 8 | const devServer = { 9 | hot: true, 10 | noInfo: false, 11 | quiet: false, 12 | port: 8000, 13 | // #https://github.com/webpack/webpack-dev-server/issues/882 14 | disableHostCheck: true, 15 | headers: { 16 | 'Access-Control-Allow-Origin': '*', 17 | 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept' 18 | }, 19 | inline: true, 20 | historyApiFallback: { 21 | index: '/' 22 | }, 23 | stats: { 24 | colors: true, 25 | modules: false 26 | }, 27 | contentBase: path.resolve(__dirname, './dist'), 28 | publicPath: '/' 29 | }; 30 | 31 | module.exports = { 32 | context: path.resolve(__dirname, '.'), 33 | entry: { 34 | app: [ 35 | 'webpack/hot/dev-server', 36 | `webpack-dev-server/client?http://localhost:8000/`, 37 | path.resolve(__dirname, './page/index.js') 38 | ] 39 | }, 40 | output: { 41 | filename: '[name].js', 42 | path: devServer.contentBase, 43 | publicPath: devServer.publicPath, 44 | sourceMapFilename: '[file].map', 45 | chunkFilename: '[name].js' 46 | }, 47 | devtool: 'source-map', 48 | module: { 49 | rules: [ 50 | { 51 | test: /\.vue$/, 52 | use: [{ 53 | loader: 'vue-loader', 54 | options: { 55 | esModule: false 56 | } 57 | }] 58 | }, 59 | { 60 | test: /\.js$/, 61 | exclude: /node_modules/, 62 | loader: 'babel-loader' 63 | }, 64 | { 65 | test: /\.less$/, 66 | use: ['vue-style-loader', 'css-loader', 'less-loader'] 67 | }, 68 | { 69 | test: /\.css$/, 70 | use: ['vue-style-loader', 'css-loader'] 71 | } 72 | ] 73 | }, 74 | 75 | resolve: { 76 | extensions: ['.vue', '.js'], 77 | modules: [path.join(__dirname, '../node_modules')], 78 | alias: { 79 | 'vue$': 'vue/dist/vue.js', 80 | revuejs: path.resolve(__dirname, '../src/index.js') 81 | } 82 | }, 83 | 84 | resolveLoader: { 85 | modules: [path.join(__dirname, '../node_modules')] 86 | }, 87 | 88 | performance: { 89 | hints: false 90 | }, 91 | 92 | devServer, 93 | 94 | plugins: [ 95 | new webpack.HotModuleReplacementPlugin(), 96 | new webpack.NoEmitOnErrorsPlugin(), 97 | 98 | new HtmlWebpackPlugin({ 99 | filename: 'index.html', 100 | template: 'index.html', 101 | inject: true, 102 | minify: { 103 | removeComments: true, 104 | collapseWhitespace: true, 105 | removeAttributeQuotes: false 106 | } 107 | }), 108 | 109 | new OpenBrowserPlugin({ url: url }) 110 | ] 111 | }; 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![build pass](https://api.travis-ci.org/dwqs/revuejs.svg?branch=master)](https://travis-ci.org/dwqs/revuejs) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com) ![npm-version](https://img.shields.io/npm/v/revuejs.svg) ![license](https://img.shields.io/npm/l/revuejs.svg) ![bower-license](https://img.shields.io/bower/l/revuejs.svg) 2 | 3 | # revuejs 4 | :rabbit2: A tiny, light and handy state management for vuejs 2, writing less verbose code. 5 | 6 | ## Installation 7 | Install the pkg with npm: 8 | ``` 9 | npm install revuejs --save 10 | ``` 11 | or yarn 12 | ``` 13 | yarn add revuejs 14 | ``` 15 | or bower 16 | ``` 17 | bower install revuejs 18 | ``` 19 | You can also hot-link the CDN version: https://unpkg.com/revuejs/dist/index.js, `Revuejs` is exposed to `window` object. 20 | 21 | ## Basic Uasage 22 | #### 1. create a module 23 | ```js 24 | // hello.js 25 | export default { 26 | namespace: 'hello', 27 | state: { 28 | title: 'hello' 29 | }, 30 | actions: { 31 | changeTitle(state, payload) { 32 | // return a new state 33 | return Object.assign({}, state, { 34 | title: payload.title 35 | }); 36 | }, 37 | 38 | async testAsync(state, payload) { 39 | await Promise.resolve(2); 40 | if(err) { 41 | return { 42 | msg: 'request error' 43 | } 44 | } 45 | return { 46 | title: 'async test' 47 | }; 48 | } 49 | } 50 | } 51 | ``` 52 | 53 | #### 2. create modules using the module you created 54 | ```js 55 | // modules/index.js 56 | import Vue from 'vue'; 57 | import Revuejs, { Modules } from 'revuejs'; 58 | 59 | Vue.use(Revuejs); 60 | 61 | import hello from 'path/to/hello'; 62 | import otherModule from 'path/to/other-module'; 63 | 64 | const modules = new Modules({ 65 | hello, 66 | otherModule 67 | // others 68 | }); 69 | 70 | export default modules; 71 | ``` 72 | 73 | #### 3. use it with Vue instance 74 | ```js 75 | import Vue from 'vue'; 76 | import modules from 'path/to/modules/index'; 77 | 78 | // ... 79 | 80 | const app = new Vue({ 81 | // ... 82 | modules, 83 | // ... 84 | }); 85 | app.$mount('#app'); 86 | ``` 87 | 88 | #### 4. combine Revuejs with Vue components 89 | ```js 90 | 96 | 119 | ``` 120 | 121 | ## Docs 122 | [View the docs here](https://github.com/dwqs/revuejs/wiki). 123 | 124 | ## Examples 125 | Running the examples: 126 | 127 | ``` 128 | npm install 129 | npm run dev # serve examples at localhost:8000 130 | ``` 131 | 132 | ## Thanks 133 | 134 | Thanks to [vuex](https://github.com/vuejs/vuex) for the head start. 135 | 136 | ## LICENSE 137 | MIT 138 | -------------------------------------------------------------------------------- /src/modules.js: -------------------------------------------------------------------------------- 1 | import { _Vue } from './install'; 2 | import { assert, isObject, hasOwn, SEP, isPromise } from './utils'; 3 | 4 | export let _root; 5 | 6 | export class Modules { 7 | constructor (modules) { 8 | assert(_Vue, `must call Vue.use(revuejs) before creating a modules instance.`); 9 | assert(this instanceof Modules, `Modules must be called with the new operator.`); 10 | assert(isObject(modules), `modules must be a plain object`); 11 | 12 | _root = this; 13 | this._modules = modules; 14 | this._modulesNamespaces = []; 15 | 16 | this._rootState = Object.create(null); 17 | this._modulesNamespaceMap = Object.create(null); 18 | this._namespaceStates = Object.create(null); 19 | this._namespaceActions = Object.create(null); 20 | 21 | this._initNamespacesModules(); 22 | this._initNamespaceStates(); 23 | this._initNamespaceActions(); 24 | this._init(_root); 25 | } 26 | 27 | _init (_root) { 28 | _root.getters = {}; 29 | const computed = {}; 30 | 31 | this._modulesNamespaces.forEach((namespace) => { 32 | const module = this._modulesNamespaceMap[namespace]; 33 | const { state } = module; 34 | this._rootState[namespace] = state; 35 | Object.keys(state).forEach((key) => { 36 | _root.getters[`${namespace}${SEP}${key}`] = function wrappedGetter () { 37 | return state[key]; 38 | }; 39 | }); 40 | }); 41 | 42 | // use a Vue instance to store the state tree 43 | // and initialize the store vm, which is responsible for the reactivity 44 | _root._vm = new _Vue({ 45 | data: { 46 | $$state: this._rootState 47 | }, 48 | computed 49 | }); 50 | } 51 | 52 | _initNamespacesModules () { 53 | Object.keys(this._modules).map((key) => { 54 | const namespace = this._modules[key].namespace; 55 | const module = this._modules[key]; 56 | 57 | assert(!hasOwn(this._modulesNamespaceMap, namespace), `the module key ${namespace} has been duplicate declaration.`); 58 | assert(namespace, `the namespace of ${key} module must be defined`); 59 | assert(typeof namespace === 'string', `the namespace of ${key} module must be a string.`); 60 | assert(/^[a-z]+$/.test(namespace), `the namespace of ${key} module must be defined used lower-case.`); 61 | 62 | this._modulesNamespaceMap[namespace] = module; 63 | this._modulesNamespaces.push(namespace); 64 | // _Vue.set(this._modulesNamespaceMap[namespace], namespace, module.state) 65 | }); 66 | } 67 | 68 | _initNamespaceStates () { 69 | this._modulesNamespaces.forEach((namespace) => { 70 | const { state } = this._modulesNamespaceMap[namespace]; 71 | 72 | assert(isObject(state), `the state of the module named ${namespace} must be a plain object`); 73 | 74 | Object.keys(state).forEach((key) => { 75 | assert(!hasOwn(this._namespaceStates, `${namespace}${SEP}${key}`), `the ${key} of the state object in the module named ${namespace} has been duplicate declaration.`); 76 | this._namespaceStates[`${namespace}${SEP}${key}`] = state[key]; 77 | }); 78 | }); 79 | } 80 | 81 | _initNamespaceActions () { 82 | this._modulesNamespaces.forEach((namespace) => { 83 | const module = this._modulesNamespaceMap[namespace]; 84 | const { actions, state } = module; 85 | 86 | assert(isObject(actions), `the actions of the module named ${namespace} must be a plain object.`); 87 | 88 | Object.keys(actions).forEach((key) => { 89 | assert(!hasOwn(this._namespaceActions, `${namespace}${SEP}${key}`), `the ${key} action of the module named ${namespace} has been duplicate declaration.`); 90 | this._namespaceActions[`${namespace}${SEP}${key}`] = function wrappedActionHandler (payload) { 91 | let res = actions[key].call(module, state, payload); 92 | if (isPromise(res)) { 93 | res.then((data) => { 94 | this._changeModuleState(module, data); 95 | }).catch((e) => { 96 | // do nothing 97 | // assert(false, `async error in _initNamespaceActions: ${e.message}`); 98 | }); 99 | } else { 100 | // wrap a promise 101 | res = Promise.resolve(res); 102 | this._changeModuleState(module, res); 103 | } 104 | return res; 105 | }; 106 | }); 107 | }); 108 | } 109 | 110 | _changeModuleState (module, res) { 111 | let batchs = []; 112 | Object.keys(res).forEach((key) => { 113 | if (typeof module.state[key] !== 'undefined') { 114 | module.state[key] = res[key]; 115 | batchs.push(`${module.namespace}${SEP}${key}`); 116 | } 117 | }); 118 | batchs.forEach((key) => { 119 | this.getters[key](); 120 | }); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /test/modules.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import Vue from 'vue'; 3 | import awaitTo from 'async-await-error-handling'; 4 | import Revuejs, { Modules, mergeActions, mergeProps } from '../dist/index'; 5 | 6 | let counter; 7 | let todo; 8 | let modules; 9 | 10 | test.beforeEach(t => { 11 | Vue.use(Revuejs); 12 | counter = { 13 | namespace: 'counter', 14 | state: { 15 | count: 0, 16 | title: 'test count' 17 | }, 18 | actions: { 19 | increase (state, payload) { 20 | let newCount = state.count + payload; 21 | return Object.assign({}, state, { 22 | count: newCount 23 | }); 24 | }, 25 | decrease (state, payload) { 26 | let newCount = state.count - payload; 27 | return { 28 | count: newCount 29 | }; 30 | }, 31 | resolvedPromise (state, payload) { 32 | return new Promise(resolve => { 33 | let newCount = state.count + payload; 34 | resolve({ 35 | count: newCount 36 | }); 37 | }); 38 | }, 39 | rejectedPromise (state, payload) { 40 | return new Promise((resolve, reject) => { 41 | reject(new Error('rejected error')); 42 | }); 43 | } 44 | } 45 | }; 46 | todo = { 47 | namespace: 'todo', 48 | state: { 49 | total: 0, 50 | list: [], 51 | title: 'test todo' 52 | }, 53 | actions: { 54 | addTodo (state, payload) { 55 | state.list.push(payload.item); 56 | return { 57 | list: state.list, 58 | total: state.list.length 59 | }; 60 | }, 61 | deleteTodo (state, payload) { 62 | state.list.splice(payload.index, 1); 63 | return Object.assign({}, state, { 64 | list: state.list, 65 | total: state.list.length 66 | }); 67 | }, 68 | 69 | async testAsync (state, payload) { 70 | let text = await Promise.resolve('testAsync'); 71 | return { 72 | item: text 73 | }; 74 | }, 75 | 76 | async asyncAddTodo (state, payload) { 77 | let { item } = await this.actions.testAsync(state, payload); 78 | state.list.push(item); 79 | return { 80 | list: state.list, 81 | total: state.list.length 82 | }; 83 | } 84 | } 85 | }; 86 | modules = new Modules({ 87 | counter, 88 | todo 89 | }); 90 | }); 91 | 92 | test('same prop in module', (t) => { 93 | t.plan(2); 94 | 95 | const vm = new Vue({ 96 | modules, 97 | computed: mergeProps({ 98 | 'countTitle': 'counter.title', 99 | 'todoTitle': 'todo.title' 100 | }) 101 | }); 102 | 103 | t.is(vm.countTitle, 'test count'); 104 | t.is(vm.todoTitle, 'test todo'); 105 | }); 106 | 107 | test('sync actions', (t) => { 108 | t.plan(3); 109 | 110 | const vm = new Vue({ 111 | modules, 112 | computed: mergeProps(['counter.count']), 113 | methods: mergeActions(['counter.increase', 'counter.decrease']) 114 | }); 115 | 116 | t.is(vm.count, 0); 117 | 118 | vm.increase(5); 119 | 120 | t.is(vm.count, counter.state.count); 121 | 122 | vm.decrease(2); 123 | vm.decrease(6); 124 | 125 | t.is(vm.count, counter.state.count); 126 | }); 127 | 128 | test('action with object style', (t) => { 129 | t.plan(9); 130 | 131 | const vm = new Vue({ 132 | modules, 133 | computed: mergeProps(['todo.total', 'todo.list']), 134 | methods: mergeActions(['todo.addTodo', 'todo.deleteTodo']) 135 | }); 136 | 137 | t.is(vm.total, 0); 138 | 139 | vm.addTodo({ 140 | item: 'item1' 141 | }); 142 | vm.addTodo({ 143 | item: 'item2' 144 | }); 145 | 146 | t.is(vm.total, todo.state.total); 147 | t.deepEqual(vm.list, ['item1', 'item2']); 148 | t.deepEqual(vm.list, todo.state.list); 149 | t.deepEqual(vm.list[1], 'item2'); 150 | 151 | vm.deleteTodo({ 152 | index: 0 153 | }); 154 | 155 | t.is(vm.total, todo.state.total); 156 | t.deepEqual(vm.list, ['item2']); 157 | t.deepEqual(vm.list, todo.state.list); 158 | t.deepEqual(vm.list[0], 'item2'); 159 | }); 160 | 161 | test.serial('action return resolved promise', async t => { 162 | t.plan(5); 163 | 164 | const vm = new Vue({ 165 | modules, 166 | computed: mergeProps(['counter.count']), 167 | methods: mergeActions(['counter.resolvedPromise']) 168 | }); 169 | 170 | t.is(vm.count, 0); 171 | 172 | let res = vm.resolvedPromise(100); 173 | const [err, data] = await awaitTo(res); 174 | 175 | t.is(vm.count, 100); 176 | t.falsy(err, false); 177 | t.deepEqual({count: 100}, data); 178 | t.is(typeof res.then, 'function'); 179 | }); 180 | 181 | test.serial('action return rejected promise', async t => { 182 | t.plan(5); 183 | 184 | const vm = new Vue({ 185 | modules, 186 | computed: mergeProps(['counter.count']), 187 | methods: mergeActions(['counter.rejectedPromise', 'counter.increase']) 188 | }); 189 | 190 | t.is(vm.count, 0); 191 | 192 | vm.increase(50); 193 | 194 | let res = await t.throws(vm.rejectedPromise(20)); 195 | const [err, data] = await awaitTo(vm.rejectedPromise(20)); 196 | 197 | t.is(res.message, 'rejected error'); 198 | t.is(err.message, 'rejected error'); 199 | t.is(data, null); 200 | }); 201 | 202 | test.serial('composing actions with async/await', async t => { 203 | t.plan(5); 204 | 205 | const vm = new Vue({ 206 | modules, 207 | computed: mergeProps(['todo.total', 'todo.list']), 208 | methods: mergeActions(['todo.asyncAddTodo']) 209 | }); 210 | 211 | t.is(vm.total, 0); 212 | t.deepEqual(vm.list, []); 213 | 214 | await vm.asyncAddTodo(); 215 | 216 | t.is(vm.total, 1); 217 | t.deepEqual(vm.list, todo.state.list); 218 | t.deepEqual(vm.list, ['testAsync']); 219 | }); 220 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | (function (global, factory) { 2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : 3 | typeof define === 'function' && define.amd ? define(['exports'], factory) : 4 | (factory((global.Revuejs = {}))); 5 | }(this, (function (exports) { 'use strict'; 6 | 7 | function unwrapExports (x) { 8 | return x && x.__esModule ? x['default'] : x; 9 | } 10 | 11 | function createCommonjsModule(fn, module) { 12 | return module = { exports: {} }, fn(module, module.exports), module.exports; 13 | } 14 | 15 | var _defined = function (it) { 16 | if (it == undefined) throw TypeError("Can't call method on " + it); 17 | return it; 18 | }; 19 | 20 | var _toObject = function (it) { 21 | return Object(_defined(it)); 22 | }; 23 | 24 | var hasOwnProperty = {}.hasOwnProperty; 25 | var _has = function (it, key) { 26 | return hasOwnProperty.call(it, key); 27 | }; 28 | 29 | var toString = {}.toString; 30 | var _cof = function (it) { 31 | return toString.call(it).slice(8, -1); 32 | }; 33 | 34 | var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) { 35 | return _cof(it) == 'String' ? it.split('') : Object(it); 36 | }; 37 | 38 | var _toIobject = function (it) { 39 | return _iobject(_defined(it)); 40 | }; 41 | 42 | var ceil = Math.ceil; 43 | var floor = Math.floor; 44 | var _toInteger = function (it) { 45 | return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); 46 | }; 47 | 48 | var min = Math.min; 49 | var _toLength = function (it) { 50 | return it > 0 ? min(_toInteger(it), 0x1fffffffffffff) : 0; 51 | }; 52 | 53 | var max = Math.max; 54 | var min$1 = Math.min; 55 | var _toAbsoluteIndex = function (index, length) { 56 | index = _toInteger(index); 57 | return index < 0 ? max(index + length, 0) : min$1(index, length); 58 | }; 59 | 60 | var _arrayIncludes = function (IS_INCLUDES) { 61 | return function ($this, el, fromIndex) { 62 | var O = _toIobject($this); 63 | var length = _toLength(O.length); 64 | var index = _toAbsoluteIndex(fromIndex, length); 65 | var value; 66 | if (IS_INCLUDES && el != el) while (length > index) { 67 | value = O[index++]; 68 | if (value != value) return true; 69 | } else for (;length > index; index++) if (IS_INCLUDES || index in O) { 70 | if (O[index] === el) return IS_INCLUDES || index || 0; 71 | } return !IS_INCLUDES && -1; 72 | }; 73 | }; 74 | 75 | var _global = createCommonjsModule(function (module) { 76 | var global = module.exports = typeof window != 'undefined' && window.Math == Math 77 | ? window : typeof self != 'undefined' && self.Math == Math ? self 78 | : Function('return this')(); 79 | if (typeof __g == 'number') __g = global; 80 | }); 81 | 82 | var SHARED = '__core-js_shared__'; 83 | var store = _global[SHARED] || (_global[SHARED] = {}); 84 | var _shared = function (key) { 85 | return store[key] || (store[key] = {}); 86 | }; 87 | 88 | var id = 0; 89 | var px = Math.random(); 90 | var _uid = function (key) { 91 | return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); 92 | }; 93 | 94 | var shared = _shared('keys'); 95 | var _sharedKey = function (key) { 96 | return shared[key] || (shared[key] = _uid(key)); 97 | }; 98 | 99 | var arrayIndexOf = _arrayIncludes(false); 100 | var IE_PROTO = _sharedKey('IE_PROTO'); 101 | var _objectKeysInternal = function (object, names) { 102 | var O = _toIobject(object); 103 | var i = 0; 104 | var result = []; 105 | var key; 106 | for (key in O) if (key != IE_PROTO) _has(O, key) && result.push(key); 107 | while (names.length > i) if (_has(O, key = names[i++])) { 108 | ~arrayIndexOf(result, key) || result.push(key); 109 | } 110 | return result; 111 | }; 112 | 113 | var _enumBugKeys = ( 114 | 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' 115 | ).split(','); 116 | 117 | var _objectKeys = Object.keys || function keys(O) { 118 | return _objectKeysInternal(O, _enumBugKeys); 119 | }; 120 | 121 | var _core = createCommonjsModule(function (module) { 122 | var core = module.exports = { version: '2.5.0' }; 123 | if (typeof __e == 'number') __e = core; 124 | }); 125 | 126 | var _aFunction = function (it) { 127 | if (typeof it != 'function') throw TypeError(it + ' is not a function!'); 128 | return it; 129 | }; 130 | 131 | var _ctx = function (fn, that, length) { 132 | _aFunction(fn); 133 | if (that === undefined) return fn; 134 | switch (length) { 135 | case 1: return function (a) { 136 | return fn.call(that, a); 137 | }; 138 | case 2: return function (a, b) { 139 | return fn.call(that, a, b); 140 | }; 141 | case 3: return function (a, b, c) { 142 | return fn.call(that, a, b, c); 143 | }; 144 | } 145 | return function ( ) { 146 | return fn.apply(that, arguments); 147 | }; 148 | }; 149 | 150 | var _isObject = function (it) { 151 | return typeof it === 'object' ? it !== null : typeof it === 'function'; 152 | }; 153 | 154 | var _anObject = function (it) { 155 | if (!_isObject(it)) throw TypeError(it + ' is not an object!'); 156 | return it; 157 | }; 158 | 159 | var _fails = function (exec) { 160 | try { 161 | return !!exec(); 162 | } catch (e) { 163 | return true; 164 | } 165 | }; 166 | 167 | var _descriptors = !_fails(function () { 168 | return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7; 169 | }); 170 | 171 | var document$1 = _global.document; 172 | var is = _isObject(document$1) && _isObject(document$1.createElement); 173 | var _domCreate = function (it) { 174 | return is ? document$1.createElement(it) : {}; 175 | }; 176 | 177 | var _ie8DomDefine = !_descriptors && !_fails(function () { 178 | return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7; 179 | }); 180 | 181 | var _toPrimitive = function (it, S) { 182 | if (!_isObject(it)) return it; 183 | var fn, val; 184 | if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; 185 | if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val; 186 | if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; 187 | throw TypeError("Can't convert object to primitive value"); 188 | }; 189 | 190 | var dP = Object.defineProperty; 191 | var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) { 192 | _anObject(O); 193 | P = _toPrimitive(P, true); 194 | _anObject(Attributes); 195 | if (_ie8DomDefine) try { 196 | return dP(O, P, Attributes); 197 | } catch (e) { } 198 | if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!'); 199 | if ('value' in Attributes) O[P] = Attributes.value; 200 | return O; 201 | }; 202 | var _objectDp = { 203 | f: f 204 | }; 205 | 206 | var _propertyDesc = function (bitmap, value) { 207 | return { 208 | enumerable: !(bitmap & 1), 209 | configurable: !(bitmap & 2), 210 | writable: !(bitmap & 4), 211 | value: value 212 | }; 213 | }; 214 | 215 | var _hide = _descriptors ? function (object, key, value) { 216 | return _objectDp.f(object, key, _propertyDesc(1, value)); 217 | } : function (object, key, value) { 218 | object[key] = value; 219 | return object; 220 | }; 221 | 222 | var PROTOTYPE = 'prototype'; 223 | var $export = function (type, name, source) { 224 | var IS_FORCED = type & $export.F; 225 | var IS_GLOBAL = type & $export.G; 226 | var IS_STATIC = type & $export.S; 227 | var IS_PROTO = type & $export.P; 228 | var IS_BIND = type & $export.B; 229 | var IS_WRAP = type & $export.W; 230 | var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {}); 231 | var expProto = exports[PROTOTYPE]; 232 | var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] : (_global[name] || {})[PROTOTYPE]; 233 | var key, own, out; 234 | if (IS_GLOBAL) source = name; 235 | for (key in source) { 236 | own = !IS_FORCED && target && target[key] !== undefined; 237 | if (own && key in exports) continue; 238 | out = own ? target[key] : source[key]; 239 | exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] 240 | : IS_BIND && own ? _ctx(out, _global) 241 | : IS_WRAP && target[key] == out ? (function (C) { 242 | var F = function (a, b, c) { 243 | if (this instanceof C) { 244 | switch (arguments.length) { 245 | case 0: return new C(); 246 | case 1: return new C(a); 247 | case 2: return new C(a, b); 248 | } return new C(a, b, c); 249 | } return C.apply(this, arguments); 250 | }; 251 | F[PROTOTYPE] = C[PROTOTYPE]; 252 | return F; 253 | })(out) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out; 254 | if (IS_PROTO) { 255 | (exports.virtual || (exports.virtual = {}))[key] = out; 256 | if (type & $export.R && expProto && !expProto[key]) _hide(expProto, key, out); 257 | } 258 | } 259 | }; 260 | $export.F = 1; 261 | $export.G = 2; 262 | $export.S = 4; 263 | $export.P = 8; 264 | $export.B = 16; 265 | $export.W = 32; 266 | $export.U = 64; 267 | $export.R = 128; 268 | var _export = $export; 269 | 270 | var _objectSap = function (KEY, exec) { 271 | var fn = (_core.Object || {})[KEY] || Object[KEY]; 272 | var exp = {}; 273 | exp[KEY] = exec(fn); 274 | _export(_export.S + _export.F * _fails(function () { fn(1); }), 'Object', exp); 275 | }; 276 | 277 | _objectSap('keys', function () { 278 | return function keys(it) { 279 | return _objectKeys(_toObject(it)); 280 | }; 281 | }); 282 | 283 | var keys$1 = _core.Object.keys; 284 | 285 | var keys = createCommonjsModule(function (module) { 286 | module.exports = { "default": keys$1, __esModule: true }; 287 | }); 288 | var _Object$keys = unwrapExports(keys); 289 | 290 | var _stringAt = function (TO_STRING) { 291 | return function (that, pos) { 292 | var s = String(_defined(that)); 293 | var i = _toInteger(pos); 294 | var l = s.length; 295 | var a, b; 296 | if (i < 0 || i >= l) return TO_STRING ? '' : undefined; 297 | a = s.charCodeAt(i); 298 | return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff 299 | ? TO_STRING ? s.charAt(i) : a 300 | : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000; 301 | }; 302 | }; 303 | 304 | var _library = true; 305 | 306 | var _redefine = _hide; 307 | 308 | var _iterators = {}; 309 | 310 | var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties) { 311 | _anObject(O); 312 | var keys = _objectKeys(Properties); 313 | var length = keys.length; 314 | var i = 0; 315 | var P; 316 | while (length > i) _objectDp.f(O, P = keys[i++], Properties[P]); 317 | return O; 318 | }; 319 | 320 | var document$2 = _global.document; 321 | var _html = document$2 && document$2.documentElement; 322 | 323 | var IE_PROTO$1 = _sharedKey('IE_PROTO'); 324 | var Empty = function () { }; 325 | var PROTOTYPE$1 = 'prototype'; 326 | var createDict = function () { 327 | var iframe = _domCreate('iframe'); 328 | var i = _enumBugKeys.length; 329 | var lt = '<'; 330 | var gt = '>'; 331 | var iframeDocument; 332 | iframe.style.display = 'none'; 333 | _html.appendChild(iframe); 334 | iframe.src = 'javascript:'; 335 | iframeDocument = iframe.contentWindow.document; 336 | iframeDocument.open(); 337 | iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt); 338 | iframeDocument.close(); 339 | createDict = iframeDocument.F; 340 | while (i--) delete createDict[PROTOTYPE$1][_enumBugKeys[i]]; 341 | return createDict(); 342 | }; 343 | var _objectCreate = Object.create || function create(O, Properties) { 344 | var result; 345 | if (O !== null) { 346 | Empty[PROTOTYPE$1] = _anObject(O); 347 | result = new Empty(); 348 | Empty[PROTOTYPE$1] = null; 349 | result[IE_PROTO$1] = O; 350 | } else result = createDict(); 351 | return Properties === undefined ? result : _objectDps(result, Properties); 352 | }; 353 | 354 | var _wks = createCommonjsModule(function (module) { 355 | var store = _shared('wks'); 356 | var Symbol = _global.Symbol; 357 | var USE_SYMBOL = typeof Symbol == 'function'; 358 | var $exports = module.exports = function (name) { 359 | return store[name] || (store[name] = 360 | USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : _uid)('Symbol.' + name)); 361 | }; 362 | $exports.store = store; 363 | }); 364 | 365 | var def = _objectDp.f; 366 | var TAG = _wks('toStringTag'); 367 | var _setToStringTag = function (it, tag, stat) { 368 | if (it && !_has(it = stat ? it : it.prototype, TAG)) def(it, TAG, { configurable: true, value: tag }); 369 | }; 370 | 371 | var IteratorPrototype = {}; 372 | _hide(IteratorPrototype, _wks('iterator'), function () { return this; }); 373 | var _iterCreate = function (Constructor, NAME, next) { 374 | Constructor.prototype = _objectCreate(IteratorPrototype, { next: _propertyDesc(1, next) }); 375 | _setToStringTag(Constructor, NAME + ' Iterator'); 376 | }; 377 | 378 | var IE_PROTO$2 = _sharedKey('IE_PROTO'); 379 | var ObjectProto = Object.prototype; 380 | var _objectGpo = Object.getPrototypeOf || function (O) { 381 | O = _toObject(O); 382 | if (_has(O, IE_PROTO$2)) return O[IE_PROTO$2]; 383 | if (typeof O.constructor == 'function' && O instanceof O.constructor) { 384 | return O.constructor.prototype; 385 | } return O instanceof Object ? ObjectProto : null; 386 | }; 387 | 388 | var ITERATOR = _wks('iterator'); 389 | var BUGGY = !([].keys && 'next' in [].keys()); 390 | var FF_ITERATOR = '@@iterator'; 391 | var KEYS = 'keys'; 392 | var VALUES = 'values'; 393 | var returnThis = function () { return this; }; 394 | var _iterDefine = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) { 395 | _iterCreate(Constructor, NAME, next); 396 | var getMethod = function (kind) { 397 | if (!BUGGY && kind in proto) return proto[kind]; 398 | switch (kind) { 399 | case KEYS: return function keys() { return new Constructor(this, kind); }; 400 | case VALUES: return function values() { return new Constructor(this, kind); }; 401 | } return function entries() { return new Constructor(this, kind); }; 402 | }; 403 | var TAG = NAME + ' Iterator'; 404 | var DEF_VALUES = DEFAULT == VALUES; 405 | var VALUES_BUG = false; 406 | var proto = Base.prototype; 407 | var $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT]; 408 | var $default = $native || getMethod(DEFAULT); 409 | var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined; 410 | var $anyNative = NAME == 'Array' ? proto.entries || $native : $native; 411 | var methods, key, IteratorPrototype; 412 | if ($anyNative) { 413 | IteratorPrototype = _objectGpo($anyNative.call(new Base())); 414 | if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) { 415 | _setToStringTag(IteratorPrototype, TAG, true); 416 | if (!_library && !_has(IteratorPrototype, ITERATOR)) _hide(IteratorPrototype, ITERATOR, returnThis); 417 | } 418 | } 419 | if (DEF_VALUES && $native && $native.name !== VALUES) { 420 | VALUES_BUG = true; 421 | $default = function values() { return $native.call(this); }; 422 | } 423 | if ((!_library || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])) { 424 | _hide(proto, ITERATOR, $default); 425 | } 426 | _iterators[NAME] = $default; 427 | _iterators[TAG] = returnThis; 428 | if (DEFAULT) { 429 | methods = { 430 | values: DEF_VALUES ? $default : getMethod(VALUES), 431 | keys: IS_SET ? $default : getMethod(KEYS), 432 | entries: $entries 433 | }; 434 | if (FORCED) for (key in methods) { 435 | if (!(key in proto)) _redefine(proto, key, methods[key]); 436 | } else _export(_export.P + _export.F * (BUGGY || VALUES_BUG), NAME, methods); 437 | } 438 | return methods; 439 | }; 440 | 441 | var $at = _stringAt(true); 442 | _iterDefine(String, 'String', function (iterated) { 443 | this._t = String(iterated); 444 | this._i = 0; 445 | }, function () { 446 | var O = this._t; 447 | var index = this._i; 448 | var point; 449 | if (index >= O.length) return { value: undefined, done: true }; 450 | point = $at(O, index); 451 | this._i += point.length; 452 | return { value: point, done: false }; 453 | }); 454 | 455 | var _addToUnscopables = function () { }; 456 | 457 | var _iterStep = function (done, value) { 458 | return { value: value, done: !!done }; 459 | }; 460 | 461 | var es6_array_iterator = _iterDefine(Array, 'Array', function (iterated, kind) { 462 | this._t = _toIobject(iterated); 463 | this._i = 0; 464 | this._k = kind; 465 | }, function () { 466 | var O = this._t; 467 | var kind = this._k; 468 | var index = this._i++; 469 | if (!O || index >= O.length) { 470 | this._t = undefined; 471 | return _iterStep(1); 472 | } 473 | if (kind == 'keys') return _iterStep(0, index); 474 | if (kind == 'values') return _iterStep(0, O[index]); 475 | return _iterStep(0, [index, O[index]]); 476 | }, 'values'); 477 | _iterators.Arguments = _iterators.Array; 478 | _addToUnscopables('keys'); 479 | _addToUnscopables('values'); 480 | _addToUnscopables('entries'); 481 | 482 | var TO_STRING_TAG = _wks('toStringTag'); 483 | var DOMIterables = ('CSSRuleList,CSSStyleDeclaration,CSSValueList,ClientRectList,DOMRectList,DOMStringList,' + 484 | 'DOMTokenList,DataTransferItemList,FileList,HTMLAllCollection,HTMLCollection,HTMLFormElement,HTMLSelectElement,' + 485 | 'MediaList,MimeTypeArray,NamedNodeMap,NodeList,PaintRequestList,Plugin,PluginArray,SVGLengthList,SVGNumberList,' + 486 | 'SVGPathSegList,SVGPointList,SVGStringList,SVGTransformList,SourceBufferList,StyleSheetList,TextTrackCueList,' + 487 | 'TextTrackList,TouchList').split(','); 488 | for (var i = 0; i < DOMIterables.length; i++) { 489 | var NAME = DOMIterables[i]; 490 | var Collection = _global[NAME]; 491 | var proto = Collection && Collection.prototype; 492 | if (proto && !proto[TO_STRING_TAG]) _hide(proto, TO_STRING_TAG, NAME); 493 | _iterators[NAME] = _iterators.Array; 494 | } 495 | 496 | var f$1 = _wks; 497 | var _wksExt = { 498 | f: f$1 499 | }; 500 | 501 | var iterator$2 = _wksExt.f('iterator'); 502 | 503 | var iterator = createCommonjsModule(function (module) { 504 | module.exports = { "default": iterator$2, __esModule: true }; 505 | }); 506 | 507 | var _meta = createCommonjsModule(function (module) { 508 | var META = _uid('meta'); 509 | var setDesc = _objectDp.f; 510 | var id = 0; 511 | var isExtensible = Object.isExtensible || function () { 512 | return true; 513 | }; 514 | var FREEZE = !_fails(function () { 515 | return isExtensible(Object.preventExtensions({})); 516 | }); 517 | var setMeta = function (it) { 518 | setDesc(it, META, { value: { 519 | i: 'O' + ++id, 520 | w: {} 521 | } }); 522 | }; 523 | var fastKey = function (it, create) { 524 | if (!_isObject(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it; 525 | if (!_has(it, META)) { 526 | if (!isExtensible(it)) return 'F'; 527 | if (!create) return 'E'; 528 | setMeta(it); 529 | } return it[META].i; 530 | }; 531 | var getWeak = function (it, create) { 532 | if (!_has(it, META)) { 533 | if (!isExtensible(it)) return true; 534 | if (!create) return false; 535 | setMeta(it); 536 | } return it[META].w; 537 | }; 538 | var onFreeze = function (it) { 539 | if (FREEZE && meta.NEED && isExtensible(it) && !_has(it, META)) setMeta(it); 540 | return it; 541 | }; 542 | var meta = module.exports = { 543 | KEY: META, 544 | NEED: false, 545 | fastKey: fastKey, 546 | getWeak: getWeak, 547 | onFreeze: onFreeze 548 | }; 549 | }); 550 | 551 | var defineProperty = _objectDp.f; 552 | var _wksDefine = function (name) { 553 | var $Symbol = _core.Symbol || (_core.Symbol = _library ? {} : _global.Symbol || {}); 554 | if (name.charAt(0) != '_' && !(name in $Symbol)) defineProperty($Symbol, name, { value: _wksExt.f(name) }); 555 | }; 556 | 557 | var _keyof = function (object, el) { 558 | var O = _toIobject(object); 559 | var keys = _objectKeys(O); 560 | var length = keys.length; 561 | var index = 0; 562 | var key; 563 | while (length > index) if (O[key = keys[index++]] === el) return key; 564 | }; 565 | 566 | var f$2 = Object.getOwnPropertySymbols; 567 | var _objectGops = { 568 | f: f$2 569 | }; 570 | 571 | var f$3 = {}.propertyIsEnumerable; 572 | var _objectPie = { 573 | f: f$3 574 | }; 575 | 576 | var _enumKeys = function (it) { 577 | var result = _objectKeys(it); 578 | var getSymbols = _objectGops.f; 579 | if (getSymbols) { 580 | var symbols = getSymbols(it); 581 | var isEnum = _objectPie.f; 582 | var i = 0; 583 | var key; 584 | while (symbols.length > i) if (isEnum.call(it, key = symbols[i++])) result.push(key); 585 | } return result; 586 | }; 587 | 588 | var _isArray = Array.isArray || function isArray(arg) { 589 | return _cof(arg) == 'Array'; 590 | }; 591 | 592 | var hiddenKeys = _enumBugKeys.concat('length', 'prototype'); 593 | var f$5 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { 594 | return _objectKeysInternal(O, hiddenKeys); 595 | }; 596 | var _objectGopn = { 597 | f: f$5 598 | }; 599 | 600 | var gOPN$1 = _objectGopn.f; 601 | var toString$1 = {}.toString; 602 | var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames 603 | ? Object.getOwnPropertyNames(window) : []; 604 | var getWindowNames = function (it) { 605 | try { 606 | return gOPN$1(it); 607 | } catch (e) { 608 | return windowNames.slice(); 609 | } 610 | }; 611 | var f$4 = function getOwnPropertyNames(it) { 612 | return windowNames && toString$1.call(it) == '[object Window]' ? getWindowNames(it) : gOPN$1(_toIobject(it)); 613 | }; 614 | var _objectGopnExt = { 615 | f: f$4 616 | }; 617 | 618 | var gOPD$1 = Object.getOwnPropertyDescriptor; 619 | var f$6 = _descriptors ? gOPD$1 : function getOwnPropertyDescriptor(O, P) { 620 | O = _toIobject(O); 621 | P = _toPrimitive(P, true); 622 | if (_ie8DomDefine) try { 623 | return gOPD$1(O, P); 624 | } catch (e) { } 625 | if (_has(O, P)) return _propertyDesc(!_objectPie.f.call(O, P), O[P]); 626 | }; 627 | var _objectGopd = { 628 | f: f$6 629 | }; 630 | 631 | var META = _meta.KEY; 632 | var gOPD = _objectGopd.f; 633 | var dP$1 = _objectDp.f; 634 | var gOPN = _objectGopnExt.f; 635 | var $Symbol = _global.Symbol; 636 | var $JSON = _global.JSON; 637 | var _stringify = $JSON && $JSON.stringify; 638 | var PROTOTYPE$2 = 'prototype'; 639 | var HIDDEN = _wks('_hidden'); 640 | var TO_PRIMITIVE = _wks('toPrimitive'); 641 | var isEnum = {}.propertyIsEnumerable; 642 | var SymbolRegistry = _shared('symbol-registry'); 643 | var AllSymbols = _shared('symbols'); 644 | var OPSymbols = _shared('op-symbols'); 645 | var ObjectProto$1 = Object[PROTOTYPE$2]; 646 | var USE_NATIVE = typeof $Symbol == 'function'; 647 | var QObject = _global.QObject; 648 | var setter = !QObject || !QObject[PROTOTYPE$2] || !QObject[PROTOTYPE$2].findChild; 649 | var setSymbolDesc = _descriptors && _fails(function () { 650 | return _objectCreate(dP$1({}, 'a', { 651 | get: function () { return dP$1(this, 'a', { value: 7 }).a; } 652 | })).a != 7; 653 | }) ? function (it, key, D) { 654 | var protoDesc = gOPD(ObjectProto$1, key); 655 | if (protoDesc) delete ObjectProto$1[key]; 656 | dP$1(it, key, D); 657 | if (protoDesc && it !== ObjectProto$1) dP$1(ObjectProto$1, key, protoDesc); 658 | } : dP$1; 659 | var wrap = function (tag) { 660 | var sym = AllSymbols[tag] = _objectCreate($Symbol[PROTOTYPE$2]); 661 | sym._k = tag; 662 | return sym; 663 | }; 664 | var isSymbol = USE_NATIVE && typeof $Symbol.iterator == 'symbol' ? function (it) { 665 | return typeof it == 'symbol'; 666 | } : function (it) { 667 | return it instanceof $Symbol; 668 | }; 669 | var $defineProperty = function defineProperty(it, key, D) { 670 | if (it === ObjectProto$1) $defineProperty(OPSymbols, key, D); 671 | _anObject(it); 672 | key = _toPrimitive(key, true); 673 | _anObject(D); 674 | if (_has(AllSymbols, key)) { 675 | if (!D.enumerable) { 676 | if (!_has(it, HIDDEN)) dP$1(it, HIDDEN, _propertyDesc(1, {})); 677 | it[HIDDEN][key] = true; 678 | } else { 679 | if (_has(it, HIDDEN) && it[HIDDEN][key]) it[HIDDEN][key] = false; 680 | D = _objectCreate(D, { enumerable: _propertyDesc(0, false) }); 681 | } return setSymbolDesc(it, key, D); 682 | } return dP$1(it, key, D); 683 | }; 684 | var $defineProperties = function defineProperties(it, P) { 685 | _anObject(it); 686 | var keys = _enumKeys(P = _toIobject(P)); 687 | var i = 0; 688 | var l = keys.length; 689 | var key; 690 | while (l > i) $defineProperty(it, key = keys[i++], P[key]); 691 | return it; 692 | }; 693 | var $create = function create(it, P) { 694 | return P === undefined ? _objectCreate(it) : $defineProperties(_objectCreate(it), P); 695 | }; 696 | var $propertyIsEnumerable = function propertyIsEnumerable(key) { 697 | var E = isEnum.call(this, key = _toPrimitive(key, true)); 698 | if (this === ObjectProto$1 && _has(AllSymbols, key) && !_has(OPSymbols, key)) return false; 699 | return E || !_has(this, key) || !_has(AllSymbols, key) || _has(this, HIDDEN) && this[HIDDEN][key] ? E : true; 700 | }; 701 | var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(it, key) { 702 | it = _toIobject(it); 703 | key = _toPrimitive(key, true); 704 | if (it === ObjectProto$1 && _has(AllSymbols, key) && !_has(OPSymbols, key)) return; 705 | var D = gOPD(it, key); 706 | if (D && _has(AllSymbols, key) && !(_has(it, HIDDEN) && it[HIDDEN][key])) D.enumerable = true; 707 | return D; 708 | }; 709 | var $getOwnPropertyNames = function getOwnPropertyNames(it) { 710 | var names = gOPN(_toIobject(it)); 711 | var result = []; 712 | var i = 0; 713 | var key; 714 | while (names.length > i) { 715 | if (!_has(AllSymbols, key = names[i++]) && key != HIDDEN && key != META) result.push(key); 716 | } return result; 717 | }; 718 | var $getOwnPropertySymbols = function getOwnPropertySymbols(it) { 719 | var IS_OP = it === ObjectProto$1; 720 | var names = gOPN(IS_OP ? OPSymbols : _toIobject(it)); 721 | var result = []; 722 | var i = 0; 723 | var key; 724 | while (names.length > i) { 725 | if (_has(AllSymbols, key = names[i++]) && (IS_OP ? _has(ObjectProto$1, key) : true)) result.push(AllSymbols[key]); 726 | } return result; 727 | }; 728 | if (!USE_NATIVE) { 729 | $Symbol = function Symbol() { 730 | if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor!'); 731 | var tag = _uid(arguments.length > 0 ? arguments[0] : undefined); 732 | var $set = function (value) { 733 | if (this === ObjectProto$1) $set.call(OPSymbols, value); 734 | if (_has(this, HIDDEN) && _has(this[HIDDEN], tag)) this[HIDDEN][tag] = false; 735 | setSymbolDesc(this, tag, _propertyDesc(1, value)); 736 | }; 737 | if (_descriptors && setter) setSymbolDesc(ObjectProto$1, tag, { configurable: true, set: $set }); 738 | return wrap(tag); 739 | }; 740 | _redefine($Symbol[PROTOTYPE$2], 'toString', function toString() { 741 | return this._k; 742 | }); 743 | _objectGopd.f = $getOwnPropertyDescriptor; 744 | _objectDp.f = $defineProperty; 745 | _objectGopn.f = _objectGopnExt.f = $getOwnPropertyNames; 746 | _objectPie.f = $propertyIsEnumerable; 747 | _objectGops.f = $getOwnPropertySymbols; 748 | if (_descriptors && !_library) { 749 | _redefine(ObjectProto$1, 'propertyIsEnumerable', $propertyIsEnumerable, true); 750 | } 751 | _wksExt.f = function (name) { 752 | return wrap(_wks(name)); 753 | }; 754 | } 755 | _export(_export.G + _export.W + _export.F * !USE_NATIVE, { Symbol: $Symbol }); 756 | for (var es6Symbols = ( 757 | 'hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables' 758 | ).split(','), j = 0; es6Symbols.length > j;)_wks(es6Symbols[j++]); 759 | for (var wellKnownSymbols = _objectKeys(_wks.store), k = 0; wellKnownSymbols.length > k;) _wksDefine(wellKnownSymbols[k++]); 760 | _export(_export.S + _export.F * !USE_NATIVE, 'Symbol', { 761 | 'for': function (key) { 762 | return _has(SymbolRegistry, key += '') 763 | ? SymbolRegistry[key] 764 | : SymbolRegistry[key] = $Symbol(key); 765 | }, 766 | keyFor: function keyFor(key) { 767 | if (isSymbol(key)) return _keyof(SymbolRegistry, key); 768 | throw TypeError(key + ' is not a symbol!'); 769 | }, 770 | useSetter: function () { setter = true; }, 771 | useSimple: function () { setter = false; } 772 | }); 773 | _export(_export.S + _export.F * !USE_NATIVE, 'Object', { 774 | create: $create, 775 | defineProperty: $defineProperty, 776 | defineProperties: $defineProperties, 777 | getOwnPropertyDescriptor: $getOwnPropertyDescriptor, 778 | getOwnPropertyNames: $getOwnPropertyNames, 779 | getOwnPropertySymbols: $getOwnPropertySymbols 780 | }); 781 | $JSON && _export(_export.S + _export.F * (!USE_NATIVE || _fails(function () { 782 | var S = $Symbol(); 783 | return _stringify([S]) != '[null]' || _stringify({ a: S }) != '{}' || _stringify(Object(S)) != '{}'; 784 | })), 'JSON', { 785 | stringify: function stringify(it) { 786 | if (it === undefined || isSymbol(it)) return; 787 | var args = [it]; 788 | var i = 1; 789 | var replacer, $replacer; 790 | while (arguments.length > i) args.push(arguments[i++]); 791 | replacer = args[1]; 792 | if (typeof replacer == 'function') $replacer = replacer; 793 | if ($replacer || !_isArray(replacer)) replacer = function (key, value) { 794 | if ($replacer) value = $replacer.call(this, key, value); 795 | if (!isSymbol(value)) return value; 796 | }; 797 | args[1] = replacer; 798 | return _stringify.apply($JSON, args); 799 | } 800 | }); 801 | $Symbol[PROTOTYPE$2][TO_PRIMITIVE] || _hide($Symbol[PROTOTYPE$2], TO_PRIMITIVE, $Symbol[PROTOTYPE$2].valueOf); 802 | _setToStringTag($Symbol, 'Symbol'); 803 | _setToStringTag(Math, 'Math', true); 804 | _setToStringTag(_global.JSON, 'JSON', true); 805 | 806 | _wksDefine('asyncIterator'); 807 | 808 | _wksDefine('observable'); 809 | 810 | var symbol$2 = _core.Symbol; 811 | 812 | var symbol = createCommonjsModule(function (module) { 813 | module.exports = { "default": symbol$2, __esModule: true }; 814 | }); 815 | 816 | var _typeof_1 = createCommonjsModule(function (module, exports) { 817 | "use strict"; 818 | exports.__esModule = true; 819 | var _iterator2 = _interopRequireDefault(iterator); 820 | var _symbol2 = _interopRequireDefault(symbol); 821 | var _typeof = typeof _symbol2.default === "function" && typeof _iterator2.default === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof _symbol2.default === "function" && obj.constructor === _symbol2.default && obj !== _symbol2.default.prototype ? "symbol" : typeof obj; }; 822 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 823 | exports.default = typeof _symbol2.default === "function" && _typeof(_iterator2.default) === "symbol" ? function (obj) { 824 | return typeof obj === "undefined" ? "undefined" : _typeof(obj); 825 | } : function (obj) { 826 | return obj && typeof _symbol2.default === "function" && obj.constructor === _symbol2.default && obj !== _symbol2.default.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof(obj); 827 | }; 828 | }); 829 | var _typeof = unwrapExports(_typeof_1); 830 | 831 | var SEP = '.'; 832 | var isPromise = function isPromise(val) { 833 | return val && typeof val.then === 'function'; 834 | }; 835 | var assert = function assert(condition) { 836 | var msg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; 837 | if (!condition) { 838 | throw new Error('[revuejs]: ' + msg); 839 | } 840 | }; 841 | var isObject = function isObject(obj) { 842 | return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; 843 | }; 844 | var normalizeMap = function normalizeMap(map) { 845 | return Array.isArray(map) ? map.map(function (key) { 846 | return { key: key, val: key }; 847 | }) : _Object$keys(map).map(function (key) { 848 | return { key: key, val: map[key] }; 849 | }); 850 | }; 851 | var hasOwn = function hasOwn(target, prop) { 852 | return {}.hasOwnProperty.call(target, prop); 853 | }; 854 | 855 | var _Vue = void 0; 856 | function install(Vue) { 857 | var version = Number(Vue.version.split('.')[0]); 858 | assert(version >= 2, 'Only supports Vuejs 2 or higher'); 859 | if (install.installed) { 860 | return; 861 | } 862 | install.installed = true; 863 | _Vue = Vue; 864 | Vue.mixin({ 865 | beforeCreate: function beforeCreate() { 866 | var options = this.$options; 867 | if (options.modules) { 868 | this.$modules = options.modules; 869 | } else if (options.parent && options.parent.$modules) { 870 | this.$modules = options.parent.$modules; 871 | } 872 | } 873 | }); 874 | } 875 | 876 | var isEnum$1 = _objectPie.f; 877 | var _objectToArray = function (isEntries) { 878 | return function (it) { 879 | var O = _toIobject(it); 880 | var keys = _objectKeys(O); 881 | var length = keys.length; 882 | var i = 0; 883 | var result = []; 884 | var key; 885 | while (length > i) if (isEnum$1.call(O, key = keys[i++])) { 886 | result.push(isEntries ? [key, O[key]] : O[key]); 887 | } return result; 888 | }; 889 | }; 890 | 891 | var $values = _objectToArray(false); 892 | _export(_export.S, 'Object', { 893 | values: function values(it) { 894 | return $values(it); 895 | } 896 | }); 897 | 898 | var values$1 = _core.Object.values; 899 | 900 | var values = createCommonjsModule(function (module) { 901 | module.exports = { "default": values$1, __esModule: true }; 902 | }); 903 | var _Object$values = unwrapExports(values); 904 | 905 | var TAG$1 = _wks('toStringTag'); 906 | var ARG = _cof(function () { return arguments; }()) == 'Arguments'; 907 | var tryGet = function (it, key) { 908 | try { 909 | return it[key]; 910 | } catch (e) { } 911 | }; 912 | var _classof = function (it) { 913 | var O, T, B; 914 | return it === undefined ? 'Undefined' : it === null ? 'Null' 915 | : typeof (T = tryGet(O = Object(it), TAG$1)) == 'string' ? T 916 | : ARG ? _cof(O) 917 | : (B = _cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B; 918 | }; 919 | 920 | var _anInstance = function (it, Constructor, name, forbiddenField) { 921 | if (!(it instanceof Constructor) || (forbiddenField !== undefined && forbiddenField in it)) { 922 | throw TypeError(name + ': incorrect invocation!'); 923 | } return it; 924 | }; 925 | 926 | var _iterCall = function (iterator, fn, value, entries) { 927 | try { 928 | return entries ? fn(_anObject(value)[0], value[1]) : fn(value); 929 | } catch (e) { 930 | var ret = iterator['return']; 931 | if (ret !== undefined) _anObject(ret.call(iterator)); 932 | throw e; 933 | } 934 | }; 935 | 936 | var ITERATOR$1 = _wks('iterator'); 937 | var ArrayProto = Array.prototype; 938 | var _isArrayIter = function (it) { 939 | return it !== undefined && (_iterators.Array === it || ArrayProto[ITERATOR$1] === it); 940 | }; 941 | 942 | var ITERATOR$2 = _wks('iterator'); 943 | var core_getIteratorMethod = _core.getIteratorMethod = function (it) { 944 | if (it != undefined) return it[ITERATOR$2] 945 | || it['@@iterator'] 946 | || _iterators[_classof(it)]; 947 | }; 948 | 949 | var _forOf = createCommonjsModule(function (module) { 950 | var BREAK = {}; 951 | var RETURN = {}; 952 | var exports = module.exports = function (iterable, entries, fn, that, ITERATOR) { 953 | var iterFn = ITERATOR ? function () { return iterable; } : core_getIteratorMethod(iterable); 954 | var f = _ctx(fn, that, entries ? 2 : 1); 955 | var index = 0; 956 | var length, step, iterator, result; 957 | if (typeof iterFn != 'function') throw TypeError(iterable + ' is not iterable!'); 958 | if (_isArrayIter(iterFn)) for (length = _toLength(iterable.length); length > index; index++) { 959 | result = entries ? f(_anObject(step = iterable[index])[0], step[1]) : f(iterable[index]); 960 | if (result === BREAK || result === RETURN) return result; 961 | } else for (iterator = iterFn.call(iterable); !(step = iterator.next()).done;) { 962 | result = _iterCall(iterator, f, step.value, entries); 963 | if (result === BREAK || result === RETURN) return result; 964 | } 965 | }; 966 | exports.BREAK = BREAK; 967 | exports.RETURN = RETURN; 968 | }); 969 | 970 | var SPECIES = _wks('species'); 971 | var _speciesConstructor = function (O, D) { 972 | var C = _anObject(O).constructor; 973 | var S; 974 | return C === undefined || (S = _anObject(C)[SPECIES]) == undefined ? D : _aFunction(S); 975 | }; 976 | 977 | var _invoke = function (fn, args, that) { 978 | var un = that === undefined; 979 | switch (args.length) { 980 | case 0: return un ? fn() 981 | : fn.call(that); 982 | case 1: return un ? fn(args[0]) 983 | : fn.call(that, args[0]); 984 | case 2: return un ? fn(args[0], args[1]) 985 | : fn.call(that, args[0], args[1]); 986 | case 3: return un ? fn(args[0], args[1], args[2]) 987 | : fn.call(that, args[0], args[1], args[2]); 988 | case 4: return un ? fn(args[0], args[1], args[2], args[3]) 989 | : fn.call(that, args[0], args[1], args[2], args[3]); 990 | } return fn.apply(that, args); 991 | }; 992 | 993 | var process$1 = _global.process; 994 | var setTask = _global.setImmediate; 995 | var clearTask = _global.clearImmediate; 996 | var MessageChannel = _global.MessageChannel; 997 | var Dispatch = _global.Dispatch; 998 | var counter = 0; 999 | var queue = {}; 1000 | var ONREADYSTATECHANGE = 'onreadystatechange'; 1001 | var defer; 1002 | var channel; 1003 | var port; 1004 | var run = function () { 1005 | var id = +this; 1006 | if (queue.hasOwnProperty(id)) { 1007 | var fn = queue[id]; 1008 | delete queue[id]; 1009 | fn(); 1010 | } 1011 | }; 1012 | var listener = function (event) { 1013 | run.call(event.data); 1014 | }; 1015 | if (!setTask || !clearTask) { 1016 | setTask = function setImmediate(fn) { 1017 | var args = []; 1018 | var i = 1; 1019 | while (arguments.length > i) args.push(arguments[i++]); 1020 | queue[++counter] = function () { 1021 | _invoke(typeof fn == 'function' ? fn : Function(fn), args); 1022 | }; 1023 | defer(counter); 1024 | return counter; 1025 | }; 1026 | clearTask = function clearImmediate(id) { 1027 | delete queue[id]; 1028 | }; 1029 | if (_cof(process$1) == 'process') { 1030 | defer = function (id) { 1031 | process$1.nextTick(_ctx(run, id, 1)); 1032 | }; 1033 | } else if (Dispatch && Dispatch.now) { 1034 | defer = function (id) { 1035 | Dispatch.now(_ctx(run, id, 1)); 1036 | }; 1037 | } else if (MessageChannel) { 1038 | channel = new MessageChannel(); 1039 | port = channel.port2; 1040 | channel.port1.onmessage = listener; 1041 | defer = _ctx(port.postMessage, port, 1); 1042 | } else if (_global.addEventListener && typeof postMessage == 'function' && !_global.importScripts) { 1043 | defer = function (id) { 1044 | _global.postMessage(id + '', '*'); 1045 | }; 1046 | _global.addEventListener('message', listener, false); 1047 | } else if (ONREADYSTATECHANGE in _domCreate('script')) { 1048 | defer = function (id) { 1049 | _html.appendChild(_domCreate('script'))[ONREADYSTATECHANGE] = function () { 1050 | _html.removeChild(this); 1051 | run.call(id); 1052 | }; 1053 | }; 1054 | } else { 1055 | defer = function (id) { 1056 | setTimeout(_ctx(run, id, 1), 0); 1057 | }; 1058 | } 1059 | } 1060 | var _task = { 1061 | set: setTask, 1062 | clear: clearTask 1063 | }; 1064 | 1065 | var macrotask = _task.set; 1066 | var Observer = _global.MutationObserver || _global.WebKitMutationObserver; 1067 | var process$2 = _global.process; 1068 | var Promise = _global.Promise; 1069 | var isNode$1 = _cof(process$2) == 'process'; 1070 | var _microtask = function () { 1071 | var head, last, notify; 1072 | var flush = function () { 1073 | var parent, fn; 1074 | if (isNode$1 && (parent = process$2.domain)) parent.exit(); 1075 | while (head) { 1076 | fn = head.fn; 1077 | head = head.next; 1078 | try { 1079 | fn(); 1080 | } catch (e) { 1081 | if (head) notify(); 1082 | else last = undefined; 1083 | throw e; 1084 | } 1085 | } last = undefined; 1086 | if (parent) parent.enter(); 1087 | }; 1088 | if (isNode$1) { 1089 | notify = function () { 1090 | process$2.nextTick(flush); 1091 | }; 1092 | } else if (Observer) { 1093 | var toggle = true; 1094 | var node = document.createTextNode(''); 1095 | new Observer(flush).observe(node, { characterData: true }); 1096 | notify = function () { 1097 | node.data = toggle = !toggle; 1098 | }; 1099 | } else if (Promise && Promise.resolve) { 1100 | var promise = Promise.resolve(); 1101 | notify = function () { 1102 | promise.then(flush); 1103 | }; 1104 | } else { 1105 | notify = function () { 1106 | macrotask.call(_global, flush); 1107 | }; 1108 | } 1109 | return function (fn) { 1110 | var task = { fn: fn, next: undefined }; 1111 | if (last) last.next = task; 1112 | if (!head) { 1113 | head = task; 1114 | notify(); 1115 | } last = task; 1116 | }; 1117 | }; 1118 | 1119 | function PromiseCapability(C) { 1120 | var resolve, reject; 1121 | this.promise = new C(function ($$resolve, $$reject) { 1122 | if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor'); 1123 | resolve = $$resolve; 1124 | reject = $$reject; 1125 | }); 1126 | this.resolve = _aFunction(resolve); 1127 | this.reject = _aFunction(reject); 1128 | } 1129 | var f$7 = function (C) { 1130 | return new PromiseCapability(C); 1131 | }; 1132 | var _newPromiseCapability = { 1133 | f: f$7 1134 | }; 1135 | 1136 | var _perform = function (exec) { 1137 | try { 1138 | return { e: false, v: exec() }; 1139 | } catch (e) { 1140 | return { e: true, v: e }; 1141 | } 1142 | }; 1143 | 1144 | var _promiseResolve = function (C, x) { 1145 | var promiseCapability = _newPromiseCapability.f(C); 1146 | var resolve = promiseCapability.resolve; 1147 | resolve(x); 1148 | return promiseCapability.promise; 1149 | }; 1150 | 1151 | var _redefineAll = function (target, src, safe) { 1152 | for (var key in src) { 1153 | if (safe && target[key]) target[key] = src[key]; 1154 | else _hide(target, key, src[key]); 1155 | } return target; 1156 | }; 1157 | 1158 | var SPECIES$1 = _wks('species'); 1159 | var _setSpecies = function (KEY) { 1160 | var C = typeof _core[KEY] == 'function' ? _core[KEY] : _global[KEY]; 1161 | if (_descriptors && C && !C[SPECIES$1]) _objectDp.f(C, SPECIES$1, { 1162 | configurable: true, 1163 | get: function () { return this; } 1164 | }); 1165 | }; 1166 | 1167 | var ITERATOR$3 = _wks('iterator'); 1168 | var SAFE_CLOSING = false; 1169 | try { 1170 | var riter = [7][ITERATOR$3](); 1171 | riter['return'] = function () { SAFE_CLOSING = true; }; 1172 | Array.from(riter, function () { throw 2; }); 1173 | } catch (e) { } 1174 | var _iterDetect = function (exec, skipClosing) { 1175 | if (!skipClosing && !SAFE_CLOSING) return false; 1176 | var safe = false; 1177 | try { 1178 | var arr = [7]; 1179 | var iter = arr[ITERATOR$3](); 1180 | iter.next = function () { return { done: safe = true }; }; 1181 | arr[ITERATOR$3] = function () { return iter; }; 1182 | exec(arr); 1183 | } catch (e) { } 1184 | return safe; 1185 | }; 1186 | 1187 | var task = _task.set; 1188 | var microtask = _microtask(); 1189 | var PROMISE = 'Promise'; 1190 | var TypeError$1 = _global.TypeError; 1191 | var process = _global.process; 1192 | var $Promise = _global[PROMISE]; 1193 | var isNode = _classof(process) == 'process'; 1194 | var empty = function () { }; 1195 | var Internal; 1196 | var newGenericPromiseCapability; 1197 | var OwnPromiseCapability; 1198 | var Wrapper; 1199 | var newPromiseCapability = newGenericPromiseCapability = _newPromiseCapability.f; 1200 | var USE_NATIVE$1 = !!function () { 1201 | try { 1202 | var promise = $Promise.resolve(1); 1203 | var FakePromise = (promise.constructor = {})[_wks('species')] = function (exec) { 1204 | exec(empty, empty); 1205 | }; 1206 | return (isNode || typeof PromiseRejectionEvent == 'function') && promise.then(empty) instanceof FakePromise; 1207 | } catch (e) { } 1208 | }(); 1209 | var sameConstructor = _library ? function (a, b) { 1210 | return a === b || a === $Promise && b === Wrapper; 1211 | } : function (a, b) { 1212 | return a === b; 1213 | }; 1214 | var isThenable = function (it) { 1215 | var then; 1216 | return _isObject(it) && typeof (then = it.then) == 'function' ? then : false; 1217 | }; 1218 | var notify = function (promise, isReject) { 1219 | if (promise._n) return; 1220 | promise._n = true; 1221 | var chain = promise._c; 1222 | microtask(function () { 1223 | var value = promise._v; 1224 | var ok = promise._s == 1; 1225 | var i = 0; 1226 | var run = function (reaction) { 1227 | var handler = ok ? reaction.ok : reaction.fail; 1228 | var resolve = reaction.resolve; 1229 | var reject = reaction.reject; 1230 | var domain = reaction.domain; 1231 | var result, then; 1232 | try { 1233 | if (handler) { 1234 | if (!ok) { 1235 | if (promise._h == 2) onHandleUnhandled(promise); 1236 | promise._h = 1; 1237 | } 1238 | if (handler === true) result = value; 1239 | else { 1240 | if (domain) domain.enter(); 1241 | result = handler(value); 1242 | if (domain) domain.exit(); 1243 | } 1244 | if (result === reaction.promise) { 1245 | reject(TypeError$1('Promise-chain cycle')); 1246 | } else if (then = isThenable(result)) { 1247 | then.call(result, resolve, reject); 1248 | } else resolve(result); 1249 | } else reject(value); 1250 | } catch (e) { 1251 | reject(e); 1252 | } 1253 | }; 1254 | while (chain.length > i) run(chain[i++]); 1255 | promise._c = []; 1256 | promise._n = false; 1257 | if (isReject && !promise._h) onUnhandled(promise); 1258 | }); 1259 | }; 1260 | var onUnhandled = function (promise) { 1261 | task.call(_global, function () { 1262 | var value = promise._v; 1263 | var unhandled = isUnhandled(promise); 1264 | var result, handler, console; 1265 | if (unhandled) { 1266 | result = _perform(function () { 1267 | if (isNode) { 1268 | process.emit('unhandledRejection', value, promise); 1269 | } else if (handler = _global.onunhandledrejection) { 1270 | handler({ promise: promise, reason: value }); 1271 | } else if ((console = _global.console) && console.error) { 1272 | console.error('Unhandled promise rejection', value); 1273 | } 1274 | }); 1275 | promise._h = isNode || isUnhandled(promise) ? 2 : 1; 1276 | } promise._a = undefined; 1277 | if (unhandled && result.e) throw result.v; 1278 | }); 1279 | }; 1280 | var isUnhandled = function (promise) { 1281 | if (promise._h == 1) return false; 1282 | var chain = promise._a || promise._c; 1283 | var i = 0; 1284 | var reaction; 1285 | while (chain.length > i) { 1286 | reaction = chain[i++]; 1287 | if (reaction.fail || !isUnhandled(reaction.promise)) return false; 1288 | } return true; 1289 | }; 1290 | var onHandleUnhandled = function (promise) { 1291 | task.call(_global, function () { 1292 | var handler; 1293 | if (isNode) { 1294 | process.emit('rejectionHandled', promise); 1295 | } else if (handler = _global.onrejectionhandled) { 1296 | handler({ promise: promise, reason: promise._v }); 1297 | } 1298 | }); 1299 | }; 1300 | var $reject = function (value) { 1301 | var promise = this; 1302 | if (promise._d) return; 1303 | promise._d = true; 1304 | promise = promise._w || promise; 1305 | promise._v = value; 1306 | promise._s = 2; 1307 | if (!promise._a) promise._a = promise._c.slice(); 1308 | notify(promise, true); 1309 | }; 1310 | var $resolve = function (value) { 1311 | var promise = this; 1312 | var then; 1313 | if (promise._d) return; 1314 | promise._d = true; 1315 | promise = promise._w || promise; 1316 | try { 1317 | if (promise === value) throw TypeError$1("Promise can't be resolved itself"); 1318 | if (then = isThenable(value)) { 1319 | microtask(function () { 1320 | var wrapper = { _w: promise, _d: false }; 1321 | try { 1322 | then.call(value, _ctx($resolve, wrapper, 1), _ctx($reject, wrapper, 1)); 1323 | } catch (e) { 1324 | $reject.call(wrapper, e); 1325 | } 1326 | }); 1327 | } else { 1328 | promise._v = value; 1329 | promise._s = 1; 1330 | notify(promise, false); 1331 | } 1332 | } catch (e) { 1333 | $reject.call({ _w: promise, _d: false }, e); 1334 | } 1335 | }; 1336 | if (!USE_NATIVE$1) { 1337 | $Promise = function Promise(executor) { 1338 | _anInstance(this, $Promise, PROMISE, '_h'); 1339 | _aFunction(executor); 1340 | Internal.call(this); 1341 | try { 1342 | executor(_ctx($resolve, this, 1), _ctx($reject, this, 1)); 1343 | } catch (err) { 1344 | $reject.call(this, err); 1345 | } 1346 | }; 1347 | Internal = function Promise(executor) { 1348 | this._c = []; 1349 | this._a = undefined; 1350 | this._s = 0; 1351 | this._d = false; 1352 | this._v = undefined; 1353 | this._h = 0; 1354 | this._n = false; 1355 | }; 1356 | Internal.prototype = _redefineAll($Promise.prototype, { 1357 | then: function then(onFulfilled, onRejected) { 1358 | var reaction = newPromiseCapability(_speciesConstructor(this, $Promise)); 1359 | reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true; 1360 | reaction.fail = typeof onRejected == 'function' && onRejected; 1361 | reaction.domain = isNode ? process.domain : undefined; 1362 | this._c.push(reaction); 1363 | if (this._a) this._a.push(reaction); 1364 | if (this._s) notify(this, false); 1365 | return reaction.promise; 1366 | }, 1367 | 'catch': function (onRejected) { 1368 | return this.then(undefined, onRejected); 1369 | } 1370 | }); 1371 | OwnPromiseCapability = function () { 1372 | var promise = new Internal(); 1373 | this.promise = promise; 1374 | this.resolve = _ctx($resolve, promise, 1); 1375 | this.reject = _ctx($reject, promise, 1); 1376 | }; 1377 | _newPromiseCapability.f = newPromiseCapability = function (C) { 1378 | return sameConstructor($Promise, C) 1379 | ? new OwnPromiseCapability(C) 1380 | : newGenericPromiseCapability(C); 1381 | }; 1382 | } 1383 | _export(_export.G + _export.W + _export.F * !USE_NATIVE$1, { Promise: $Promise }); 1384 | _setToStringTag($Promise, PROMISE); 1385 | _setSpecies(PROMISE); 1386 | Wrapper = _core[PROMISE]; 1387 | _export(_export.S + _export.F * !USE_NATIVE$1, PROMISE, { 1388 | reject: function reject(r) { 1389 | var capability = newPromiseCapability(this); 1390 | var $$reject = capability.reject; 1391 | $$reject(r); 1392 | return capability.promise; 1393 | } 1394 | }); 1395 | _export(_export.S + _export.F * (_library || !USE_NATIVE$1), PROMISE, { 1396 | resolve: function resolve(x) { 1397 | if (x instanceof $Promise && sameConstructor(x.constructor, this)) return x; 1398 | return _promiseResolve(this, x); 1399 | } 1400 | }); 1401 | _export(_export.S + _export.F * !(USE_NATIVE$1 && _iterDetect(function (iter) { 1402 | $Promise.all(iter)['catch'](empty); 1403 | })), PROMISE, { 1404 | all: function all(iterable) { 1405 | var C = this; 1406 | var capability = newPromiseCapability(C); 1407 | var resolve = capability.resolve; 1408 | var reject = capability.reject; 1409 | var result = _perform(function () { 1410 | var values = []; 1411 | var index = 0; 1412 | var remaining = 1; 1413 | _forOf(iterable, false, function (promise) { 1414 | var $index = index++; 1415 | var alreadyCalled = false; 1416 | values.push(undefined); 1417 | remaining++; 1418 | C.resolve(promise).then(function (value) { 1419 | if (alreadyCalled) return; 1420 | alreadyCalled = true; 1421 | values[$index] = value; 1422 | --remaining || resolve(values); 1423 | }, reject); 1424 | }); 1425 | --remaining || resolve(values); 1426 | }); 1427 | if (result.e) reject(result.v); 1428 | return capability.promise; 1429 | }, 1430 | race: function race(iterable) { 1431 | var C = this; 1432 | var capability = newPromiseCapability(C); 1433 | var reject = capability.reject; 1434 | var result = _perform(function () { 1435 | _forOf(iterable, false, function (promise) { 1436 | C.resolve(promise).then(capability.resolve, reject); 1437 | }); 1438 | }); 1439 | if (result.e) reject(result.v); 1440 | return capability.promise; 1441 | } 1442 | }); 1443 | 1444 | _export(_export.P + _export.R, 'Promise', { 'finally': function (onFinally) { 1445 | var C = _speciesConstructor(this, _core.Promise || _global.Promise); 1446 | var isFunction = typeof onFinally == 'function'; 1447 | return this.then( 1448 | isFunction ? function (x) { 1449 | return _promiseResolve(C, onFinally()).then(function () { return x; }); 1450 | } : onFinally, 1451 | isFunction ? function (e) { 1452 | return _promiseResolve(C, onFinally()).then(function () { throw e; }); 1453 | } : onFinally 1454 | ); 1455 | } }); 1456 | 1457 | _export(_export.S, 'Promise', { 'try': function (callbackfn) { 1458 | var promiseCapability = _newPromiseCapability.f(this); 1459 | var result = _perform(callbackfn); 1460 | (result.e ? promiseCapability.reject : promiseCapability.resolve)(result.v); 1461 | return promiseCapability.promise; 1462 | } }); 1463 | 1464 | var promise$1 = _core.Promise; 1465 | 1466 | var promise = createCommonjsModule(function (module) { 1467 | module.exports = { "default": promise$1, __esModule: true }; 1468 | }); 1469 | var _Promise = unwrapExports(promise); 1470 | 1471 | _export(_export.S, 'Object', { create: _objectCreate }); 1472 | 1473 | var $Object = _core.Object; 1474 | var create$1 = function create(P, D) { 1475 | return $Object.create(P, D); 1476 | }; 1477 | 1478 | var create = createCommonjsModule(function (module) { 1479 | module.exports = { "default": create$1, __esModule: true }; 1480 | }); 1481 | var _Object$create = unwrapExports(create); 1482 | 1483 | var classCallCheck = createCommonjsModule(function (module, exports) { 1484 | "use strict"; 1485 | exports.__esModule = true; 1486 | exports.default = function (instance, Constructor) { 1487 | if (!(instance instanceof Constructor)) { 1488 | throw new TypeError("Cannot call a class as a function"); 1489 | } 1490 | }; 1491 | }); 1492 | var _classCallCheck = unwrapExports(classCallCheck); 1493 | 1494 | _export(_export.S + _export.F * !_descriptors, 'Object', { defineProperty: _objectDp.f }); 1495 | 1496 | var $Object$1 = _core.Object; 1497 | var defineProperty$3 = function defineProperty(it, key, desc) { 1498 | return $Object$1.defineProperty(it, key, desc); 1499 | }; 1500 | 1501 | var defineProperty$1 = createCommonjsModule(function (module) { 1502 | module.exports = { "default": defineProperty$3, __esModule: true }; 1503 | }); 1504 | 1505 | var createClass = createCommonjsModule(function (module, exports) { 1506 | "use strict"; 1507 | exports.__esModule = true; 1508 | var _defineProperty2 = _interopRequireDefault(defineProperty$1); 1509 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 1510 | exports.default = function () { 1511 | function defineProperties(target, props) { 1512 | for (var i = 0; i < props.length; i++) { 1513 | var descriptor = props[i]; 1514 | descriptor.enumerable = descriptor.enumerable || false; 1515 | descriptor.configurable = true; 1516 | if ("value" in descriptor) descriptor.writable = true; 1517 | (0, _defineProperty2.default)(target, descriptor.key, descriptor); 1518 | } 1519 | } 1520 | return function (Constructor, protoProps, staticProps) { 1521 | if (protoProps) defineProperties(Constructor.prototype, protoProps); 1522 | if (staticProps) defineProperties(Constructor, staticProps); 1523 | return Constructor; 1524 | }; 1525 | }(); 1526 | }); 1527 | var _createClass = unwrapExports(createClass); 1528 | 1529 | var _root = void 0; 1530 | var Modules = function () { 1531 | function Modules(modules) { 1532 | _classCallCheck(this, Modules); 1533 | assert(_Vue, 'must call Vue.use(revuejs) before creating a modules instance.'); 1534 | assert(this instanceof Modules, 'Modules must be called with the new operator.'); 1535 | assert(isObject(modules), 'modules must be a plain object'); 1536 | _root = this; 1537 | this._modules = modules; 1538 | this._modulesNamespaces = []; 1539 | this._rootState = _Object$create(null); 1540 | this._modulesNamespaceMap = _Object$create(null); 1541 | this._namespaceStates = _Object$create(null); 1542 | this._namespaceActions = _Object$create(null); 1543 | this._initNamespacesModules(); 1544 | this._initNamespaceStates(); 1545 | this._initNamespaceActions(); 1546 | this._init(_root); 1547 | } 1548 | _createClass(Modules, [{ 1549 | key: '_init', 1550 | value: function _init(_root) { 1551 | var _this = this; 1552 | _root.getters = {}; 1553 | var computed = {}; 1554 | this._modulesNamespaces.forEach(function (namespace) { 1555 | var module = _this._modulesNamespaceMap[namespace]; 1556 | var state = module.state; 1557 | _this._rootState[namespace] = state; 1558 | _Object$keys(state).forEach(function (key) { 1559 | _root.getters['' + namespace + SEP + key] = function wrappedGetter() { 1560 | return state[key]; 1561 | }; 1562 | }); 1563 | }); 1564 | _root._vm = new _Vue({ 1565 | data: { 1566 | $$state: this._rootState 1567 | }, 1568 | computed: computed 1569 | }); 1570 | } 1571 | }, { 1572 | key: '_initNamespacesModules', 1573 | value: function _initNamespacesModules() { 1574 | var _this2 = this; 1575 | _Object$keys(this._modules).map(function (key) { 1576 | var namespace = _this2._modules[key].namespace; 1577 | var module = _this2._modules[key]; 1578 | assert(!hasOwn(_this2._modulesNamespaceMap, namespace), 'the module key ' + namespace + ' has been duplicate declaration.'); 1579 | assert(namespace, 'the namespace of ' + key + ' module must be defined'); 1580 | assert(typeof namespace === 'string', 'the namespace of ' + key + ' module must be a string.'); 1581 | assert(/^[a-z]+$/.test(namespace), 'the namespace of ' + key + ' module must be defined used lower-case.'); 1582 | _this2._modulesNamespaceMap[namespace] = module; 1583 | _this2._modulesNamespaces.push(namespace); 1584 | }); 1585 | } 1586 | }, { 1587 | key: '_initNamespaceStates', 1588 | value: function _initNamespaceStates() { 1589 | var _this3 = this; 1590 | this._modulesNamespaces.forEach(function (namespace) { 1591 | var state = _this3._modulesNamespaceMap[namespace].state; 1592 | assert(isObject(state), 'the state of the module named ' + namespace + ' must be a plain object'); 1593 | _Object$keys(state).forEach(function (key) { 1594 | assert(!hasOwn(_this3._namespaceStates, '' + namespace + SEP + key), 'the ' + key + ' of the state object in the module named ' + namespace + ' has been duplicate declaration.'); 1595 | _this3._namespaceStates['' + namespace + SEP + key] = state[key]; 1596 | }); 1597 | }); 1598 | } 1599 | }, { 1600 | key: '_initNamespaceActions', 1601 | value: function _initNamespaceActions() { 1602 | var _this4 = this; 1603 | this._modulesNamespaces.forEach(function (namespace) { 1604 | var module = _this4._modulesNamespaceMap[namespace]; 1605 | var actions = module.actions, 1606 | state = module.state; 1607 | assert(isObject(actions), 'the actions of the module named ' + namespace + ' must be a plain object.'); 1608 | _Object$keys(actions).forEach(function (key) { 1609 | assert(!hasOwn(_this4._namespaceActions, '' + namespace + SEP + key), 'the ' + key + ' action of the module named ' + namespace + ' has been duplicate declaration.'); 1610 | _this4._namespaceActions['' + namespace + SEP + key] = function wrappedActionHandler(payload) { 1611 | var _this5 = this; 1612 | var res = actions[key].call(module, state, payload); 1613 | if (isPromise(res)) { 1614 | res.then(function (data) { 1615 | _this5._changeModuleState(module, data); 1616 | }).catch(function (e) { 1617 | }); 1618 | } else { 1619 | res = _Promise.resolve(res); 1620 | this._changeModuleState(module, res); 1621 | } 1622 | return res; 1623 | }; 1624 | }); 1625 | }); 1626 | } 1627 | }, { 1628 | key: '_changeModuleState', 1629 | value: function _changeModuleState(module, res) { 1630 | var _this6 = this; 1631 | var batchs = []; 1632 | _Object$keys(res).forEach(function (key) { 1633 | if (typeof module.state[key] !== 'undefined') { 1634 | module.state[key] = res[key]; 1635 | batchs.push('' + module.namespace + SEP + key); 1636 | } 1637 | }); 1638 | batchs.forEach(function (key) { 1639 | _this6.getters[key](); 1640 | }); 1641 | } 1642 | }]); 1643 | return Modules; 1644 | }(); 1645 | 1646 | var mergeActions = function mergeActions(actions) { 1647 | var _validActions = _Object$keys(_root._namespaceActions); 1648 | var actionsVals = void 0; 1649 | var res = {}; 1650 | if (Array.isArray(actions)) { 1651 | actionsVals = actions; 1652 | } else { 1653 | assert(isObject(actions), 'the parameter of mergeActions must be a array or plain object'); 1654 | actionsVals = _Object$values(actions); 1655 | } 1656 | if (!actionsVals.length) { 1657 | return res; 1658 | } 1659 | actionsVals.forEach(function (action) { 1660 | assert(_validActions.includes(action), 'the ' + action + ' action is invalid'); 1661 | }); 1662 | normalizeMap(actions).forEach(function (_ref) { 1663 | var key = _ref.key, 1664 | val = _ref.val; 1665 | var k = key.indexOf(SEP) > -1 ? key.split(SEP)[1] : key; 1666 | res[k] = function mappedAction() { 1667 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 1668 | args[_key] = arguments[_key]; 1669 | } 1670 | return _root._namespaceActions[val].apply(_root, [].concat(args)); 1671 | }; 1672 | }); 1673 | return res; 1674 | }; 1675 | var mergeProps = function mergeProps(props) { 1676 | var _validProps = _Object$keys(_root._namespaceStates); 1677 | var propsVals = void 0; 1678 | var res = {}; 1679 | if (Array.isArray(props)) { 1680 | propsVals = props; 1681 | } else { 1682 | assert(isObject(props), 'the parameter of mergeProps must be a array or plain object'); 1683 | propsVals = _Object$values(props); 1684 | } 1685 | if (!propsVals.length) { 1686 | return res; 1687 | } 1688 | propsVals.forEach(function (prop) { 1689 | assert(_validProps.includes(prop), 'the ' + prop + ' prop is invalid'); 1690 | }); 1691 | normalizeMap(props).forEach(function (_ref2) { 1692 | var key = _ref2.key, 1693 | val = _ref2.val; 1694 | var k = key.indexOf(SEP) > -1 ? key.split(SEP)[1] : key; 1695 | res[k] = function mappedProps() { 1696 | return _root.getters[val](); 1697 | }; 1698 | }); 1699 | return res; 1700 | }; 1701 | 1702 | var Revuejs = { 1703 | install: install 1704 | }; 1705 | if (typeof window !== 'undefined' && window.Vue) { 1706 | window.Vue.use(Revuejs); 1707 | } 1708 | 1709 | exports['default'] = Revuejs; 1710 | exports.mergeActions = mergeActions; 1711 | exports.mergeProps = mergeProps; 1712 | exports.Modules = Modules; 1713 | 1714 | Object.defineProperty(exports, '__esModule', { value: true }); 1715 | 1716 | }))); 1717 | --------------------------------------------------------------------------------