├── .babelrc ├── .gitattributes ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── bower.json ├── dist └── index.js ├── example ├── app.vue ├── index.js └── models │ └── test.js ├── package-lock.json ├── package.json ├── rollup.build.config.js ├── rollup.config.js ├── src ├── index.ts ├── install.ts ├── mixin.ts ├── options.ts └── utils.ts ├── test └── index.js ├── tsconfig.json ├── tslint.json └── types ├── connect.d.ts ├── index.d.ts ├── install.d.ts ├── mixin.d.ts ├── options.d.ts └── utils.d.ts /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "es2015", 5 | { 6 | "modules": false 7 | } 8 | ] 9 | ], 10 | "plugins": ["transform-runtime"] 11 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=TypeScript -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .DS_Store 3 | bower_components 4 | node_modules 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | lib 12 | dist 13 | package-lock.json -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | .gitignore 3 | .vscode 4 | .npmrc 5 | .babelrc 6 | *.js 7 | node_modules 8 | example 9 | lib 10 | .gitattributes 11 | .travis.yml 12 | tslint.json 13 | bower.json -------------------------------------------------------------------------------- /.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 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![build pass](https://api.travis-ci.org/dwqs/vue-mobx.svg?branch=master)](https://travis-ci.org/dwqs/vue-mobx) ![npm-version](https://img.shields.io/npm/v/vue-mobx.svg) ![license](https://img.shields.io/npm/l/vue-mobx.svg) ![bower-license](https://img.shields.io/bower/l/vue-mobx.svg) 2 | 3 | # vue-mobx 4 | 5 | Mobx binding for Vue. 6 | 7 | > Only supports Vuejs 2.x & Mobx 2.2.x or higher. 8 | 9 | ## Installation 10 | Install the pkg with npm: 11 | 12 | ``` 13 | npm install vue-mobx --save 14 | ``` 15 | 16 | or yarn 17 | 18 | ``` 19 | yarn add vue-mobx 20 | ``` 21 | 22 | or bower 23 | 24 | ``` 25 | bower install vue-mobx 26 | ``` 27 | 28 | ## Usage 29 | 30 | Obviously it works with Mobx and Vuejs, install via NPM: `npm i --save mobx vue vue-mobx`: 31 | 32 | #### 1. install vue-mobx plugin: 33 | 34 | ```js 35 | // entry.js 36 | import Vue from 'vue'; 37 | import {observable, isObservable, toJS} from 'mobx'; 38 | import VueMobx from 'vue-mobx'; 39 | 40 | Vue.use(VueMobx, { 41 | toJS: toJS, // must 42 | isObservable: isObservable, // must 43 | observable: observable, // optional 44 | }); 45 | ``` 46 | #### 2. create models: 47 | 48 | ```js 49 | // create models 50 | 51 | import {observable, action} from 'mobx'; 52 | 53 | class Test { 54 | @observable 55 | count = 0; 56 | 57 | @action.bound 58 | changeCount(){ 59 | ++this.count; 60 | } 61 | } 62 | 63 | const test = new Test(); 64 | export default test; 65 | ``` 66 | 67 | #### 3. use models in vue component: 68 | 69 | ```js 70 | // in vue component 71 | 77 | 86 | ``` 87 | 88 | There is a full [example](https://github.com/dwqs/vue-mobx/tree/master/example). 89 | 90 | ## LICENSE 91 | 92 | MIT 93 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-mobx", 3 | "main": "dist/index.js", 4 | "description": "Mobx binding for Vuejs 2", 5 | "authors": ["pomysky@gmail.com"], 6 | "license": "MIT", 7 | "ignore": [ 8 | "*", 9 | "!dist", 10 | "!LICENSE", 11 | "!README.md" 12 | ] 13 | } -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | (function (global, factory) { 2 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue')) : 3 | typeof define === 'function' && define.amd ? define(['vue'], factory) : 4 | (global.VueMobx = factory(global.Vue)); 5 | }(this, (function (Vue) { 'use strict'; 6 | 7 | Vue = Vue && 'default' in Vue ? Vue['default'] : Vue; 8 | 9 | function unwrapExports (x) { 10 | return x && x.__esModule ? x['default'] : x; 11 | } 12 | 13 | function createCommonjsModule(fn, module) { 14 | return module = { exports: {} }, fn(module, module.exports), module.exports; 15 | } 16 | 17 | // 7.1.4 ToInteger 18 | var ceil = Math.ceil; 19 | var floor = Math.floor; 20 | var _toInteger = function(it){ 21 | return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); 22 | }; 23 | 24 | // 7.2.1 RequireObjectCoercible(argument) 25 | var _defined = function(it){ 26 | if(it == undefined)throw TypeError("Can't call method on " + it); 27 | return it; 28 | }; 29 | 30 | // true -> String#at 31 | // false -> String#codePointAt 32 | var _stringAt = function(TO_STRING){ 33 | return function(that, pos){ 34 | var s = String(_defined(that)) 35 | , i = _toInteger(pos) 36 | , l = s.length 37 | , a, b; 38 | if(i < 0 || i >= l)return TO_STRING ? '' : undefined; 39 | a = s.charCodeAt(i); 40 | return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff 41 | ? TO_STRING ? s.charAt(i) : a 42 | : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000; 43 | }; 44 | }; 45 | 46 | var _library = true; 47 | 48 | var _global = createCommonjsModule(function (module) { 49 | // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 50 | var global = module.exports = typeof window != 'undefined' && window.Math == Math 51 | ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); 52 | if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef 53 | }); 54 | 55 | var _core = createCommonjsModule(function (module) { 56 | var core = module.exports = {version: '2.4.0'}; 57 | if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef 58 | }); 59 | 60 | var _aFunction = function(it){ 61 | if(typeof it != 'function')throw TypeError(it + ' is not a function!'); 62 | return it; 63 | }; 64 | 65 | // optional / simple context binding 66 | 67 | var _ctx = function(fn, that, length){ 68 | _aFunction(fn); 69 | if(that === undefined)return fn; 70 | switch(length){ 71 | case 1: return function(a){ 72 | return fn.call(that, a); 73 | }; 74 | case 2: return function(a, b){ 75 | return fn.call(that, a, b); 76 | }; 77 | case 3: return function(a, b, c){ 78 | return fn.call(that, a, b, c); 79 | }; 80 | } 81 | return function(/* ...args */){ 82 | return fn.apply(that, arguments); 83 | }; 84 | }; 85 | 86 | var _isObject = function(it){ 87 | return typeof it === 'object' ? it !== null : typeof it === 'function'; 88 | }; 89 | 90 | var _anObject = function(it){ 91 | if(!_isObject(it))throw TypeError(it + ' is not an object!'); 92 | return it; 93 | }; 94 | 95 | var _fails = function(exec){ 96 | try { 97 | return !!exec(); 98 | } catch(e){ 99 | return true; 100 | } 101 | }; 102 | 103 | // Thank's IE8 for his funny defineProperty 104 | var _descriptors = !_fails(function(){ 105 | return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7; 106 | }); 107 | 108 | var document$1 = _global.document; 109 | var is = _isObject(document$1) && _isObject(document$1.createElement); 110 | var _domCreate = function(it){ 111 | return is ? document$1.createElement(it) : {}; 112 | }; 113 | 114 | var _ie8DomDefine = !_descriptors && !_fails(function(){ 115 | return Object.defineProperty(_domCreate('div'), 'a', {get: function(){ return 7; }}).a != 7; 116 | }); 117 | 118 | // 7.1.1 ToPrimitive(input [, PreferredType]) 119 | 120 | // instead of the ES6 spec version, we didn't implement @@toPrimitive case 121 | // and the second argument - flag - preferred type is a string 122 | var _toPrimitive = function(it, S){ 123 | if(!_isObject(it))return it; 124 | var fn, val; 125 | if(S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it)))return val; 126 | if(typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it)))return val; 127 | if(!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it)))return val; 128 | throw TypeError("Can't convert object to primitive value"); 129 | }; 130 | 131 | var dP = Object.defineProperty; 132 | 133 | var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes){ 134 | _anObject(O); 135 | P = _toPrimitive(P, true); 136 | _anObject(Attributes); 137 | if(_ie8DomDefine)try { 138 | return dP(O, P, Attributes); 139 | } catch(e){ /* empty */ } 140 | if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!'); 141 | if('value' in Attributes)O[P] = Attributes.value; 142 | return O; 143 | }; 144 | 145 | var _objectDp = { 146 | f: f 147 | }; 148 | 149 | var _propertyDesc = function(bitmap, value){ 150 | return { 151 | enumerable : !(bitmap & 1), 152 | configurable: !(bitmap & 2), 153 | writable : !(bitmap & 4), 154 | value : value 155 | }; 156 | }; 157 | 158 | var _hide = _descriptors ? function(object, key, value){ 159 | return _objectDp.f(object, key, _propertyDesc(1, value)); 160 | } : function(object, key, value){ 161 | object[key] = value; 162 | return object; 163 | }; 164 | 165 | var PROTOTYPE = 'prototype'; 166 | 167 | var $export = function(type, name, source){ 168 | var IS_FORCED = type & $export.F 169 | , IS_GLOBAL = type & $export.G 170 | , IS_STATIC = type & $export.S 171 | , IS_PROTO = type & $export.P 172 | , IS_BIND = type & $export.B 173 | , IS_WRAP = type & $export.W 174 | , exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {}) 175 | , expProto = exports[PROTOTYPE] 176 | , target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] : (_global[name] || {})[PROTOTYPE] 177 | , key, own, out; 178 | if(IS_GLOBAL)source = name; 179 | for(key in source){ 180 | // contains in native 181 | own = !IS_FORCED && target && target[key] !== undefined; 182 | if(own && key in exports)continue; 183 | // export native or passed 184 | out = own ? target[key] : source[key]; 185 | // prevent global pollution for namespaces 186 | exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] 187 | // bind timers to global for call from export context 188 | : IS_BIND && own ? _ctx(out, _global) 189 | // wrap global constructors for prevent change them in library 190 | : IS_WRAP && target[key] == out ? (function(C){ 191 | var F = function(a, b, c){ 192 | if(this instanceof C){ 193 | switch(arguments.length){ 194 | case 0: return new C; 195 | case 1: return new C(a); 196 | case 2: return new C(a, b); 197 | } return new C(a, b, c); 198 | } return C.apply(this, arguments); 199 | }; 200 | F[PROTOTYPE] = C[PROTOTYPE]; 201 | return F; 202 | // make static versions for prototype methods 203 | })(out) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out; 204 | // export proto methods to core.%CONSTRUCTOR%.methods.%NAME% 205 | if(IS_PROTO){ 206 | (exports.virtual || (exports.virtual = {}))[key] = out; 207 | // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME% 208 | if(type & $export.R && expProto && !expProto[key])_hide(expProto, key, out); 209 | } 210 | } 211 | }; 212 | // type bitmap 213 | $export.F = 1; // forced 214 | $export.G = 2; // global 215 | $export.S = 4; // static 216 | $export.P = 8; // proto 217 | $export.B = 16; // bind 218 | $export.W = 32; // wrap 219 | $export.U = 64; // safe 220 | $export.R = 128; // real proto method for `library` 221 | var _export = $export; 222 | 223 | var _redefine = _hide; 224 | 225 | var hasOwnProperty = {}.hasOwnProperty; 226 | var _has = function(it, key){ 227 | return hasOwnProperty.call(it, key); 228 | }; 229 | 230 | var _iterators = {}; 231 | 232 | var toString = {}.toString; 233 | 234 | var _cof = function(it){ 235 | return toString.call(it).slice(8, -1); 236 | }; 237 | 238 | // fallback for non-array-like ES3 and non-enumerable old V8 strings 239 | 240 | var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function(it){ 241 | return _cof(it) == 'String' ? it.split('') : Object(it); 242 | }; 243 | 244 | // to indexed object, toObject with fallback for non-array-like ES3 strings 245 | 246 | var _toIobject = function(it){ 247 | return _iobject(_defined(it)); 248 | }; 249 | 250 | // 7.1.15 ToLength 251 | var min = Math.min; 252 | var _toLength = function(it){ 253 | return it > 0 ? min(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991 254 | }; 255 | 256 | var max = Math.max; 257 | var min$1 = Math.min; 258 | var _toIndex = function(index, length){ 259 | index = _toInteger(index); 260 | return index < 0 ? max(index + length, 0) : min$1(index, length); 261 | }; 262 | 263 | // false -> Array#indexOf 264 | // true -> Array#includes 265 | 266 | var _arrayIncludes = function(IS_INCLUDES){ 267 | return function($this, el, fromIndex){ 268 | var O = _toIobject($this) 269 | , length = _toLength(O.length) 270 | , index = _toIndex(fromIndex, length) 271 | , value; 272 | // Array#includes uses SameValueZero equality algorithm 273 | if(IS_INCLUDES && el != el)while(length > index){ 274 | value = O[index++]; 275 | if(value != value)return true; 276 | // Array#toIndex ignores holes, Array#includes - not 277 | } else for(;length > index; index++)if(IS_INCLUDES || index in O){ 278 | if(O[index] === el)return IS_INCLUDES || index || 0; 279 | } return !IS_INCLUDES && -1; 280 | }; 281 | }; 282 | 283 | var SHARED = '__core-js_shared__'; 284 | var store = _global[SHARED] || (_global[SHARED] = {}); 285 | var _shared = function(key){ 286 | return store[key] || (store[key] = {}); 287 | }; 288 | 289 | var id = 0; 290 | var px = Math.random(); 291 | var _uid = function(key){ 292 | return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); 293 | }; 294 | 295 | var shared = _shared('keys'); 296 | var _sharedKey = function(key){ 297 | return shared[key] || (shared[key] = _uid(key)); 298 | }; 299 | 300 | var arrayIndexOf = _arrayIncludes(false); 301 | var IE_PROTO$1 = _sharedKey('IE_PROTO'); 302 | 303 | var _objectKeysInternal = function(object, names){ 304 | var O = _toIobject(object) 305 | , i = 0 306 | , result = [] 307 | , key; 308 | for(key in O)if(key != IE_PROTO$1)_has(O, key) && result.push(key); 309 | // Don't enum bug & hidden keys 310 | while(names.length > i)if(_has(O, key = names[i++])){ 311 | ~arrayIndexOf(result, key) || result.push(key); 312 | } 313 | return result; 314 | }; 315 | 316 | // IE 8- don't enum bug keys 317 | var _enumBugKeys = ( 318 | 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' 319 | ).split(','); 320 | 321 | // 19.1.2.14 / 15.2.3.14 Object.keys(O) 322 | 323 | 324 | var _objectKeys = Object.keys || function keys(O){ 325 | return _objectKeysInternal(O, _enumBugKeys); 326 | }; 327 | 328 | var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties){ 329 | _anObject(O); 330 | var keys = _objectKeys(Properties) 331 | , length = keys.length 332 | , i = 0 333 | , P; 334 | while(length > i)_objectDp.f(O, P = keys[i++], Properties[P]); 335 | return O; 336 | }; 337 | 338 | var _html = _global.document && document.documentElement; 339 | 340 | // 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties]) 341 | var IE_PROTO = _sharedKey('IE_PROTO'); 342 | var Empty = function(){ /* empty */ }; 343 | var PROTOTYPE$1 = 'prototype'; 344 | 345 | // Create object with fake `null` prototype: use iframe Object with cleared prototype 346 | var createDict = function(){ 347 | // Thrash, waste and sodomy: IE GC bug 348 | var iframe = _domCreate('iframe') 349 | , i = _enumBugKeys.length 350 | , lt = '<' 351 | , gt = '>' 352 | , iframeDocument; 353 | iframe.style.display = 'none'; 354 | _html.appendChild(iframe); 355 | iframe.src = 'javascript:'; // eslint-disable-line no-script-url 356 | // createDict = iframe.contentWindow.Object; 357 | // html.removeChild(iframe); 358 | iframeDocument = iframe.contentWindow.document; 359 | iframeDocument.open(); 360 | iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt); 361 | iframeDocument.close(); 362 | createDict = iframeDocument.F; 363 | while(i--)delete createDict[PROTOTYPE$1][_enumBugKeys[i]]; 364 | return createDict(); 365 | }; 366 | 367 | var _objectCreate = Object.create || function create(O, Properties){ 368 | var result; 369 | if(O !== null){ 370 | Empty[PROTOTYPE$1] = _anObject(O); 371 | result = new Empty; 372 | Empty[PROTOTYPE$1] = null; 373 | // add "__proto__" for Object.getPrototypeOf polyfill 374 | result[IE_PROTO] = O; 375 | } else result = createDict(); 376 | return Properties === undefined ? result : _objectDps(result, Properties); 377 | }; 378 | 379 | var _wks = createCommonjsModule(function (module) { 380 | var store = _shared('wks') 381 | , Symbol = _global.Symbol 382 | , USE_SYMBOL = typeof Symbol == 'function'; 383 | 384 | var $exports = module.exports = function(name){ 385 | return store[name] || (store[name] = 386 | USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : _uid)('Symbol.' + name)); 387 | }; 388 | 389 | $exports.store = store; 390 | }); 391 | 392 | var def = _objectDp.f; 393 | var TAG = _wks('toStringTag'); 394 | 395 | var _setToStringTag = function(it, tag, stat){ 396 | if(it && !_has(it = stat ? it : it.prototype, TAG))def(it, TAG, {configurable: true, value: tag}); 397 | }; 398 | 399 | var IteratorPrototype = {}; 400 | 401 | // 25.1.2.1.1 %IteratorPrototype%[@@iterator]() 402 | _hide(IteratorPrototype, _wks('iterator'), function(){ return this; }); 403 | 404 | var _iterCreate = function(Constructor, NAME, next){ 405 | Constructor.prototype = _objectCreate(IteratorPrototype, {next: _propertyDesc(1, next)}); 406 | _setToStringTag(Constructor, NAME + ' Iterator'); 407 | }; 408 | 409 | // 7.1.13 ToObject(argument) 410 | 411 | var _toObject = function(it){ 412 | return Object(_defined(it)); 413 | }; 414 | 415 | // 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O) 416 | var IE_PROTO$2 = _sharedKey('IE_PROTO'); 417 | var ObjectProto = Object.prototype; 418 | 419 | var _objectGpo = Object.getPrototypeOf || function(O){ 420 | O = _toObject(O); 421 | if(_has(O, IE_PROTO$2))return O[IE_PROTO$2]; 422 | if(typeof O.constructor == 'function' && O instanceof O.constructor){ 423 | return O.constructor.prototype; 424 | } return O instanceof Object ? ObjectProto : null; 425 | }; 426 | 427 | var ITERATOR = _wks('iterator'); 428 | var BUGGY = !([].keys && 'next' in [].keys()); 429 | var FF_ITERATOR = '@@iterator'; 430 | var KEYS = 'keys'; 431 | var VALUES = 'values'; 432 | 433 | var returnThis = function(){ return this; }; 434 | 435 | var _iterDefine = function(Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED){ 436 | _iterCreate(Constructor, NAME, next); 437 | var getMethod = function(kind){ 438 | if(!BUGGY && kind in proto)return proto[kind]; 439 | switch(kind){ 440 | case KEYS: return function keys(){ return new Constructor(this, kind); }; 441 | case VALUES: return function values(){ return new Constructor(this, kind); }; 442 | } return function entries(){ return new Constructor(this, kind); }; 443 | }; 444 | var TAG = NAME + ' Iterator' 445 | , DEF_VALUES = DEFAULT == VALUES 446 | , VALUES_BUG = false 447 | , proto = Base.prototype 448 | , $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT] 449 | , $default = $native || getMethod(DEFAULT) 450 | , $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined 451 | , $anyNative = NAME == 'Array' ? proto.entries || $native : $native 452 | , methods, key, IteratorPrototype; 453 | // Fix native 454 | if($anyNative){ 455 | IteratorPrototype = _objectGpo($anyNative.call(new Base)); 456 | if(IteratorPrototype !== Object.prototype){ 457 | // Set @@toStringTag to native iterators 458 | _setToStringTag(IteratorPrototype, TAG, true); 459 | // fix for some old engines 460 | if(!_library && !_has(IteratorPrototype, ITERATOR))_hide(IteratorPrototype, ITERATOR, returnThis); 461 | } 462 | } 463 | // fix Array#{values, @@iterator}.name in V8 / FF 464 | if(DEF_VALUES && $native && $native.name !== VALUES){ 465 | VALUES_BUG = true; 466 | $default = function values(){ return $native.call(this); }; 467 | } 468 | // Define iterator 469 | if((!_library || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])){ 470 | _hide(proto, ITERATOR, $default); 471 | } 472 | // Plug for library 473 | _iterators[NAME] = $default; 474 | _iterators[TAG] = returnThis; 475 | if(DEFAULT){ 476 | methods = { 477 | values: DEF_VALUES ? $default : getMethod(VALUES), 478 | keys: IS_SET ? $default : getMethod(KEYS), 479 | entries: $entries 480 | }; 481 | if(FORCED)for(key in methods){ 482 | if(!(key in proto))_redefine(proto, key, methods[key]); 483 | } else _export(_export.P + _export.F * (BUGGY || VALUES_BUG), NAME, methods); 484 | } 485 | return methods; 486 | }; 487 | 488 | var $at = _stringAt(true); 489 | 490 | // 21.1.3.27 String.prototype[@@iterator]() 491 | _iterDefine(String, 'String', function(iterated){ 492 | this._t = String(iterated); // target 493 | this._i = 0; // next index 494 | // 21.1.5.2.1 %StringIteratorPrototype%.next() 495 | }, function(){ 496 | var O = this._t 497 | , index = this._i 498 | , point; 499 | if(index >= O.length)return {value: undefined, done: true}; 500 | point = $at(O, index); 501 | this._i += point.length; 502 | return {value: point, done: false}; 503 | }); 504 | 505 | var _addToUnscopables = function(){ /* empty */ }; 506 | 507 | var _iterStep = function(done, value){ 508 | return {value: value, done: !!done}; 509 | }; 510 | 511 | // 22.1.3.4 Array.prototype.entries() 512 | // 22.1.3.13 Array.prototype.keys() 513 | // 22.1.3.29 Array.prototype.values() 514 | // 22.1.3.30 Array.prototype[@@iterator]() 515 | var es6_array_iterator = _iterDefine(Array, 'Array', function(iterated, kind){ 516 | this._t = _toIobject(iterated); // target 517 | this._i = 0; // next index 518 | this._k = kind; // kind 519 | // 22.1.5.2.1 %ArrayIteratorPrototype%.next() 520 | }, function(){ 521 | var O = this._t 522 | , kind = this._k 523 | , index = this._i++; 524 | if(!O || index >= O.length){ 525 | this._t = undefined; 526 | return _iterStep(1); 527 | } 528 | if(kind == 'keys' )return _iterStep(0, index); 529 | if(kind == 'values')return _iterStep(0, O[index]); 530 | return _iterStep(0, [index, O[index]]); 531 | }, 'values'); 532 | 533 | // argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7) 534 | _iterators.Arguments = _iterators.Array; 535 | 536 | _addToUnscopables('keys'); 537 | _addToUnscopables('values'); 538 | _addToUnscopables('entries'); 539 | 540 | var TO_STRING_TAG = _wks('toStringTag'); 541 | 542 | for(var collections = ['NodeList', 'DOMTokenList', 'MediaList', 'StyleSheetList', 'CSSRuleList'], i = 0; i < 5; i++){ 543 | var NAME = collections[i] 544 | , Collection = _global[NAME] 545 | , proto = Collection && Collection.prototype; 546 | if(proto && !proto[TO_STRING_TAG])_hide(proto, TO_STRING_TAG, NAME); 547 | _iterators[NAME] = _iterators.Array; 548 | } 549 | 550 | var f$1 = _wks; 551 | 552 | var _wksExt = { 553 | f: f$1 554 | }; 555 | 556 | var iterator$2 = _wksExt.f('iterator'); 557 | 558 | var iterator = createCommonjsModule(function (module) { 559 | module.exports = { "default": iterator$2, __esModule: true }; 560 | }); 561 | 562 | var _meta = createCommonjsModule(function (module) { 563 | var META = _uid('meta') 564 | , setDesc = _objectDp.f 565 | , id = 0; 566 | var isExtensible = Object.isExtensible || function(){ 567 | return true; 568 | }; 569 | var FREEZE = !_fails(function(){ 570 | return isExtensible(Object.preventExtensions({})); 571 | }); 572 | var setMeta = function(it){ 573 | setDesc(it, META, {value: { 574 | i: 'O' + ++id, // object ID 575 | w: {} // weak collections IDs 576 | }}); 577 | }; 578 | var fastKey = function(it, create){ 579 | // return primitive with prefix 580 | if(!_isObject(it))return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it; 581 | if(!_has(it, META)){ 582 | // can't set metadata to uncaught frozen object 583 | if(!isExtensible(it))return 'F'; 584 | // not necessary to add metadata 585 | if(!create)return 'E'; 586 | // add missing metadata 587 | setMeta(it); 588 | // return object ID 589 | } return it[META].i; 590 | }; 591 | var getWeak = function(it, create){ 592 | if(!_has(it, META)){ 593 | // can't set metadata to uncaught frozen object 594 | if(!isExtensible(it))return true; 595 | // not necessary to add metadata 596 | if(!create)return false; 597 | // add missing metadata 598 | setMeta(it); 599 | // return hash weak collections IDs 600 | } return it[META].w; 601 | }; 602 | // add metadata on freeze-family methods calling 603 | var onFreeze = function(it){ 604 | if(FREEZE && meta.NEED && isExtensible(it) && !_has(it, META))setMeta(it); 605 | return it; 606 | }; 607 | var meta = module.exports = { 608 | KEY: META, 609 | NEED: false, 610 | fastKey: fastKey, 611 | getWeak: getWeak, 612 | onFreeze: onFreeze 613 | }; 614 | }); 615 | 616 | var defineProperty = _objectDp.f; 617 | var _wksDefine = function(name){ 618 | var $Symbol = _core.Symbol || (_core.Symbol = _library ? {} : _global.Symbol || {}); 619 | if(name.charAt(0) != '_' && !(name in $Symbol))defineProperty($Symbol, name, {value: _wksExt.f(name)}); 620 | }; 621 | 622 | var _keyof = function(object, el){ 623 | var O = _toIobject(object) 624 | , keys = _objectKeys(O) 625 | , length = keys.length 626 | , index = 0 627 | , key; 628 | while(length > index)if(O[key = keys[index++]] === el)return key; 629 | }; 630 | 631 | var f$2 = Object.getOwnPropertySymbols; 632 | 633 | var _objectGops = { 634 | f: f$2 635 | }; 636 | 637 | var f$3 = {}.propertyIsEnumerable; 638 | 639 | var _objectPie = { 640 | f: f$3 641 | }; 642 | 643 | // all enumerable object keys, includes symbols 644 | 645 | var _enumKeys = function(it){ 646 | var result = _objectKeys(it) 647 | , getSymbols = _objectGops.f; 648 | if(getSymbols){ 649 | var symbols = getSymbols(it) 650 | , isEnum = _objectPie.f 651 | , i = 0 652 | , key; 653 | while(symbols.length > i)if(isEnum.call(it, key = symbols[i++]))result.push(key); 654 | } return result; 655 | }; 656 | 657 | // 7.2.2 IsArray(argument) 658 | 659 | var _isArray = Array.isArray || function isArray(arg){ 660 | return _cof(arg) == 'Array'; 661 | }; 662 | 663 | // 19.1.2.7 / 15.2.3.4 Object.getOwnPropertyNames(O) 664 | var hiddenKeys = _enumBugKeys.concat('length', 'prototype'); 665 | 666 | var f$5 = Object.getOwnPropertyNames || function getOwnPropertyNames(O){ 667 | return _objectKeysInternal(O, hiddenKeys); 668 | }; 669 | 670 | var _objectGopn = { 671 | f: f$5 672 | }; 673 | 674 | // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window 675 | var gOPN$1 = _objectGopn.f; 676 | var toString$1 = {}.toString; 677 | 678 | var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames 679 | ? Object.getOwnPropertyNames(window) : []; 680 | 681 | var getWindowNames = function(it){ 682 | try { 683 | return gOPN$1(it); 684 | } catch(e){ 685 | return windowNames.slice(); 686 | } 687 | }; 688 | 689 | var f$4 = function getOwnPropertyNames(it){ 690 | return windowNames && toString$1.call(it) == '[object Window]' ? getWindowNames(it) : gOPN$1(_toIobject(it)); 691 | }; 692 | 693 | var _objectGopnExt = { 694 | f: f$4 695 | }; 696 | 697 | var gOPD$1 = Object.getOwnPropertyDescriptor; 698 | 699 | var f$6 = _descriptors ? gOPD$1 : function getOwnPropertyDescriptor(O, P){ 700 | O = _toIobject(O); 701 | P = _toPrimitive(P, true); 702 | if(_ie8DomDefine)try { 703 | return gOPD$1(O, P); 704 | } catch(e){ /* empty */ } 705 | if(_has(O, P))return _propertyDesc(!_objectPie.f.call(O, P), O[P]); 706 | }; 707 | 708 | var _objectGopd = { 709 | f: f$6 710 | }; 711 | 712 | // ECMAScript 6 symbols shim 713 | var META = _meta.KEY; 714 | var gOPD = _objectGopd.f; 715 | var dP$1 = _objectDp.f; 716 | var gOPN = _objectGopnExt.f; 717 | var $Symbol = _global.Symbol; 718 | var $JSON = _global.JSON; 719 | var _stringify = $JSON && $JSON.stringify; 720 | var PROTOTYPE$2 = 'prototype'; 721 | var HIDDEN = _wks('_hidden'); 722 | var TO_PRIMITIVE = _wks('toPrimitive'); 723 | var isEnum = {}.propertyIsEnumerable; 724 | var SymbolRegistry = _shared('symbol-registry'); 725 | var AllSymbols = _shared('symbols'); 726 | var OPSymbols = _shared('op-symbols'); 727 | var ObjectProto$1 = Object[PROTOTYPE$2]; 728 | var USE_NATIVE = typeof $Symbol == 'function'; 729 | var QObject = _global.QObject; 730 | // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173 731 | var setter = !QObject || !QObject[PROTOTYPE$2] || !QObject[PROTOTYPE$2].findChild; 732 | 733 | // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687 734 | var setSymbolDesc = _descriptors && _fails(function(){ 735 | return _objectCreate(dP$1({}, 'a', { 736 | get: function(){ return dP$1(this, 'a', {value: 7}).a; } 737 | })).a != 7; 738 | }) ? function(it, key, D){ 739 | var protoDesc = gOPD(ObjectProto$1, key); 740 | if(protoDesc)delete ObjectProto$1[key]; 741 | dP$1(it, key, D); 742 | if(protoDesc && it !== ObjectProto$1)dP$1(ObjectProto$1, key, protoDesc); 743 | } : dP$1; 744 | 745 | var wrap = function(tag){ 746 | var sym = AllSymbols[tag] = _objectCreate($Symbol[PROTOTYPE$2]); 747 | sym._k = tag; 748 | return sym; 749 | }; 750 | 751 | var isSymbol = USE_NATIVE && typeof $Symbol.iterator == 'symbol' ? function(it){ 752 | return typeof it == 'symbol'; 753 | } : function(it){ 754 | return it instanceof $Symbol; 755 | }; 756 | 757 | var $defineProperty = function defineProperty(it, key, D){ 758 | if(it === ObjectProto$1)$defineProperty(OPSymbols, key, D); 759 | _anObject(it); 760 | key = _toPrimitive(key, true); 761 | _anObject(D); 762 | if(_has(AllSymbols, key)){ 763 | if(!D.enumerable){ 764 | if(!_has(it, HIDDEN))dP$1(it, HIDDEN, _propertyDesc(1, {})); 765 | it[HIDDEN][key] = true; 766 | } else { 767 | if(_has(it, HIDDEN) && it[HIDDEN][key])it[HIDDEN][key] = false; 768 | D = _objectCreate(D, {enumerable: _propertyDesc(0, false)}); 769 | } return setSymbolDesc(it, key, D); 770 | } return dP$1(it, key, D); 771 | }; 772 | var $defineProperties = function defineProperties(it, P){ 773 | _anObject(it); 774 | var keys = _enumKeys(P = _toIobject(P)) 775 | , i = 0 776 | , l = keys.length 777 | , key; 778 | while(l > i)$defineProperty(it, key = keys[i++], P[key]); 779 | return it; 780 | }; 781 | var $create = function create(it, P){ 782 | return P === undefined ? _objectCreate(it) : $defineProperties(_objectCreate(it), P); 783 | }; 784 | var $propertyIsEnumerable = function propertyIsEnumerable(key){ 785 | var E = isEnum.call(this, key = _toPrimitive(key, true)); 786 | if(this === ObjectProto$1 && _has(AllSymbols, key) && !_has(OPSymbols, key))return false; 787 | return E || !_has(this, key) || !_has(AllSymbols, key) || _has(this, HIDDEN) && this[HIDDEN][key] ? E : true; 788 | }; 789 | var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(it, key){ 790 | it = _toIobject(it); 791 | key = _toPrimitive(key, true); 792 | if(it === ObjectProto$1 && _has(AllSymbols, key) && !_has(OPSymbols, key))return; 793 | var D = gOPD(it, key); 794 | if(D && _has(AllSymbols, key) && !(_has(it, HIDDEN) && it[HIDDEN][key]))D.enumerable = true; 795 | return D; 796 | }; 797 | var $getOwnPropertyNames = function getOwnPropertyNames(it){ 798 | var names = gOPN(_toIobject(it)) 799 | , result = [] 800 | , i = 0 801 | , key; 802 | while(names.length > i){ 803 | if(!_has(AllSymbols, key = names[i++]) && key != HIDDEN && key != META)result.push(key); 804 | } return result; 805 | }; 806 | var $getOwnPropertySymbols = function getOwnPropertySymbols(it){ 807 | var IS_OP = it === ObjectProto$1 808 | , names = gOPN(IS_OP ? OPSymbols : _toIobject(it)) 809 | , result = [] 810 | , i = 0 811 | , key; 812 | while(names.length > i){ 813 | if(_has(AllSymbols, key = names[i++]) && (IS_OP ? _has(ObjectProto$1, key) : true))result.push(AllSymbols[key]); 814 | } return result; 815 | }; 816 | 817 | // 19.4.1.1 Symbol([description]) 818 | if(!USE_NATIVE){ 819 | $Symbol = function Symbol(){ 820 | if(this instanceof $Symbol)throw TypeError('Symbol is not a constructor!'); 821 | var tag = _uid(arguments.length > 0 ? arguments[0] : undefined); 822 | var $set = function(value){ 823 | if(this === ObjectProto$1)$set.call(OPSymbols, value); 824 | if(_has(this, HIDDEN) && _has(this[HIDDEN], tag))this[HIDDEN][tag] = false; 825 | setSymbolDesc(this, tag, _propertyDesc(1, value)); 826 | }; 827 | if(_descriptors && setter)setSymbolDesc(ObjectProto$1, tag, {configurable: true, set: $set}); 828 | return wrap(tag); 829 | }; 830 | _redefine($Symbol[PROTOTYPE$2], 'toString', function toString(){ 831 | return this._k; 832 | }); 833 | 834 | _objectGopd.f = $getOwnPropertyDescriptor; 835 | _objectDp.f = $defineProperty; 836 | _objectGopn.f = _objectGopnExt.f = $getOwnPropertyNames; 837 | _objectPie.f = $propertyIsEnumerable; 838 | _objectGops.f = $getOwnPropertySymbols; 839 | 840 | if(_descriptors && !_library){ 841 | _redefine(ObjectProto$1, 'propertyIsEnumerable', $propertyIsEnumerable, true); 842 | } 843 | 844 | _wksExt.f = function(name){ 845 | return wrap(_wks(name)); 846 | }; 847 | } 848 | 849 | _export(_export.G + _export.W + _export.F * !USE_NATIVE, {Symbol: $Symbol}); 850 | 851 | for(var symbols = ( 852 | // 19.4.2.2, 19.4.2.3, 19.4.2.4, 19.4.2.6, 19.4.2.8, 19.4.2.9, 19.4.2.10, 19.4.2.11, 19.4.2.12, 19.4.2.13, 19.4.2.14 853 | 'hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables' 854 | ).split(','), i$1 = 0; symbols.length > i$1; )_wks(symbols[i$1++]); 855 | 856 | for(var symbols = _objectKeys(_wks.store), i$1 = 0; symbols.length > i$1; )_wksDefine(symbols[i$1++]); 857 | 858 | _export(_export.S + _export.F * !USE_NATIVE, 'Symbol', { 859 | // 19.4.2.1 Symbol.for(key) 860 | 'for': function(key){ 861 | return _has(SymbolRegistry, key += '') 862 | ? SymbolRegistry[key] 863 | : SymbolRegistry[key] = $Symbol(key); 864 | }, 865 | // 19.4.2.5 Symbol.keyFor(sym) 866 | keyFor: function keyFor(key){ 867 | if(isSymbol(key))return _keyof(SymbolRegistry, key); 868 | throw TypeError(key + ' is not a symbol!'); 869 | }, 870 | useSetter: function(){ setter = true; }, 871 | useSimple: function(){ setter = false; } 872 | }); 873 | 874 | _export(_export.S + _export.F * !USE_NATIVE, 'Object', { 875 | // 19.1.2.2 Object.create(O [, Properties]) 876 | create: $create, 877 | // 19.1.2.4 Object.defineProperty(O, P, Attributes) 878 | defineProperty: $defineProperty, 879 | // 19.1.2.3 Object.defineProperties(O, Properties) 880 | defineProperties: $defineProperties, 881 | // 19.1.2.6 Object.getOwnPropertyDescriptor(O, P) 882 | getOwnPropertyDescriptor: $getOwnPropertyDescriptor, 883 | // 19.1.2.7 Object.getOwnPropertyNames(O) 884 | getOwnPropertyNames: $getOwnPropertyNames, 885 | // 19.1.2.8 Object.getOwnPropertySymbols(O) 886 | getOwnPropertySymbols: $getOwnPropertySymbols 887 | }); 888 | 889 | // 24.3.2 JSON.stringify(value [, replacer [, space]]) 890 | $JSON && _export(_export.S + _export.F * (!USE_NATIVE || _fails(function(){ 891 | var S = $Symbol(); 892 | // MS Edge converts symbol values to JSON as {} 893 | // WebKit converts symbol values to JSON as null 894 | // V8 throws on boxed symbols 895 | return _stringify([S]) != '[null]' || _stringify({a: S}) != '{}' || _stringify(Object(S)) != '{}'; 896 | })), 'JSON', { 897 | stringify: function stringify(it){ 898 | if(it === undefined || isSymbol(it))return; // IE8 returns string on undefined 899 | var args = [it] 900 | , i = 1 901 | , replacer, $replacer; 902 | while(arguments.length > i)args.push(arguments[i++]); 903 | replacer = args[1]; 904 | if(typeof replacer == 'function')$replacer = replacer; 905 | if($replacer || !_isArray(replacer))replacer = function(key, value){ 906 | if($replacer)value = $replacer.call(this, key, value); 907 | if(!isSymbol(value))return value; 908 | }; 909 | args[1] = replacer; 910 | return _stringify.apply($JSON, args); 911 | } 912 | }); 913 | 914 | // 19.4.3.4 Symbol.prototype[@@toPrimitive](hint) 915 | $Symbol[PROTOTYPE$2][TO_PRIMITIVE] || _hide($Symbol[PROTOTYPE$2], TO_PRIMITIVE, $Symbol[PROTOTYPE$2].valueOf); 916 | // 19.4.3.5 Symbol.prototype[@@toStringTag] 917 | _setToStringTag($Symbol, 'Symbol'); 918 | // 20.2.1.9 Math[@@toStringTag] 919 | _setToStringTag(Math, 'Math', true); 920 | // 24.3.3 JSON[@@toStringTag] 921 | _setToStringTag(_global.JSON, 'JSON', true); 922 | 923 | _wksDefine('asyncIterator'); 924 | 925 | _wksDefine('observable'); 926 | 927 | var index = _core.Symbol; 928 | 929 | var symbol = createCommonjsModule(function (module) { 930 | module.exports = { "default": index, __esModule: true }; 931 | }); 932 | 933 | var _typeof_1 = createCommonjsModule(function (module, exports) { 934 | "use strict"; 935 | 936 | exports.__esModule = true; 937 | 938 | 939 | 940 | var _iterator2 = _interopRequireDefault(iterator); 941 | 942 | 943 | 944 | var _symbol2 = _interopRequireDefault(symbol); 945 | 946 | 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; }; 947 | 948 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 949 | 950 | exports.default = typeof _symbol2.default === "function" && _typeof(_iterator2.default) === "symbol" ? function (obj) { 951 | return typeof obj === "undefined" ? "undefined" : _typeof(obj); 952 | } : function (obj) { 953 | return obj && typeof _symbol2.default === "function" && obj.constructor === _symbol2.default && obj !== _symbol2.default.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof(obj); 954 | }; 955 | }); 956 | 957 | var _typeof = unwrapExports(_typeof_1); 958 | 959 | // most Object methods by ES6 should accept primitives 960 | 961 | var _objectSap = function(KEY, exec){ 962 | var fn = (_core.Object || {})[KEY] || Object[KEY] 963 | , exp = {}; 964 | exp[KEY] = exec(fn); 965 | _export(_export.S + _export.F * _fails(function(){ fn(1); }), 'Object', exp); 966 | }; 967 | 968 | // 19.1.2.6 Object.getOwnPropertyDescriptor(O, P) 969 | var $getOwnPropertyDescriptor$1 = _objectGopd.f; 970 | 971 | _objectSap('getOwnPropertyDescriptor', function(){ 972 | return function getOwnPropertyDescriptor(it, key){ 973 | return $getOwnPropertyDescriptor$1(_toIobject(it), key); 974 | }; 975 | }); 976 | 977 | var $Object = _core.Object; 978 | var getOwnPropertyDescriptor$1 = function getOwnPropertyDescriptor(it, key){ 979 | return $Object.getOwnPropertyDescriptor(it, key); 980 | }; 981 | 982 | var getOwnPropertyDescriptor = createCommonjsModule(function (module) { 983 | module.exports = { "default": getOwnPropertyDescriptor$1, __esModule: true }; 984 | }); 985 | 986 | var _Object$getOwnPropertyDescriptor = unwrapExports(getOwnPropertyDescriptor); 987 | 988 | // 19.1.2.14 Object.keys(O) 989 | 990 | 991 | _objectSap('keys', function(){ 992 | return function keys(it){ 993 | return _objectKeys(_toObject(it)); 994 | }; 995 | }); 996 | 997 | var keys$1 = _core.Object.keys; 998 | 999 | var keys = createCommonjsModule(function (module) { 1000 | module.exports = { "default": keys$1, __esModule: true }; 1001 | }); 1002 | 1003 | var _Object$keys = unwrapExports(keys); 1004 | 1005 | // 19.1.2.7 Object.getOwnPropertyNames(O) 1006 | _objectSap('getOwnPropertyNames', function(){ 1007 | return _objectGopnExt.f; 1008 | }); 1009 | 1010 | var $Object$1 = _core.Object; 1011 | var getOwnPropertyNames$1 = function getOwnPropertyNames(it){ 1012 | return $Object$1.getOwnPropertyNames(it); 1013 | }; 1014 | 1015 | var getOwnPropertyNames = createCommonjsModule(function (module) { 1016 | module.exports = { "default": getOwnPropertyNames$1, __esModule: true }; 1017 | }); 1018 | 1019 | var _Object$getOwnPropertyNames = unwrapExports(getOwnPropertyNames); 1020 | 1021 | // 19.1.2.9 Object.getPrototypeOf(O) 1022 | 1023 | 1024 | _objectSap('getPrototypeOf', function(){ 1025 | return function getPrototypeOf(it){ 1026 | return _objectGpo(_toObject(it)); 1027 | }; 1028 | }); 1029 | 1030 | var getPrototypeOf$1 = _core.Object.getPrototypeOf; 1031 | 1032 | var getPrototypeOf = createCommonjsModule(function (module) { 1033 | module.exports = { "default": getPrototypeOf$1, __esModule: true }; 1034 | }); 1035 | 1036 | var _Object$getPrototypeOf = unwrapExports(getPrototypeOf); 1037 | 1038 | const __assign = Object.assign || function (target) { 1039 | for (var source, i = 1; i < arguments.length; i++) { 1040 | source = arguments[i]; 1041 | for (var prop in source) { 1042 | if (Object.prototype.hasOwnProperty.call(source, prop)) { 1043 | target[prop] = source[prop]; 1044 | } 1045 | } 1046 | } 1047 | return target; 1048 | }; 1049 | 1050 | var Options = function () { 1051 | function Options() {} 1052 | Options.saveOptions = function (config) { 1053 | Options.options = config; 1054 | }; 1055 | return Options; 1056 | }(); 1057 | 1058 | function isObject$1(data) { 1059 | return data !== null && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object'; 1060 | } 1061 | function assert(condition, msg) { 1062 | if (!condition) { 1063 | throw new Error("[vue-mobx]: " + msg); 1064 | } 1065 | } 1066 | var $mobx = '__mobxDidRunLazyInitializers'; 1067 | var $$mobx = '$mobx'; 1068 | function getProto(obj) { 1069 | return _Object$getPrototypeOf(obj); 1070 | } 1071 | function getOwnProps(obj) { 1072 | return _Object$getOwnPropertyNames(obj); 1073 | } 1074 | function getValidModel(models) { 1075 | var res = {}; 1076 | _Object$keys(models).forEach(function (key) { 1077 | if (Options.options.isObservable(models[key])) { 1078 | res[key] = models[key]; 1079 | } 1080 | }); 1081 | return res; 1082 | } 1083 | function getValidAction(models, methods) { 1084 | var res = {}; 1085 | _Object$keys(models).forEach(function (key) { 1086 | var props = getOwnProps(getProto(models[key])); 1087 | for (var i = 0, l = props.length; i < l; i++) { 1088 | if (typeof models[key][props[i]] === 'function' && models[key][props[i]].isMobxAction) { 1089 | assert(!methods[props[i]], "The \"" + props[i] + "\" method is already defined in methods."); 1090 | res[props[i]] = models[key][props[i]].bind(models[key]); 1091 | } 1092 | } 1093 | }); 1094 | return res; 1095 | } 1096 | 1097 | function createComputedProps(models, data, computed, vm) { 1098 | var res = {}; 1099 | _Object$keys(models).forEach(function (key) { 1100 | var model = models[key]; 1101 | var props = getOwnProps(getProto(model)); 1102 | var _loop_1 = function _loop_1(i, l) { 1103 | if (props[i] !== $mobx && props[i] !== $$mobx && props[i] !== 'constructor' && typeof model[props[i]] !== 'function') { 1104 | assert(!(props[i] in data), "The computed property \"" + props[i] + "\" is already defined in data."); 1105 | assert(!(props[i] in computed), "The computed property \"" + props[i] + "\" is already defined in computed."); 1106 | var property_1 = _Object$getOwnPropertyDescriptor(model, props[i]); 1107 | _Vue.util.defineReactive(model, props[i], null, null, true); 1108 | res[props[i]] = { 1109 | get: function get() { 1110 | return model[props[i]]; 1111 | }, 1112 | set: function set(val) { 1113 | property_1.set.call(vm, val); 1114 | } 1115 | }; 1116 | } 1117 | }; 1118 | for (var i = 0, l = props.length; i < l; i++) { 1119 | _loop_1(i, l); 1120 | } 1121 | }); 1122 | return res; 1123 | } 1124 | 1125 | function applyMixin(config) { 1126 | assert(_Vue, "must call Vue.use(VueMobx) to init vue-mobx config."); 1127 | _Vue.mixin({ 1128 | beforeCreate: function beforeCreate() { 1129 | if (this.$options.fromMobx) { 1130 | var mapModels = this.$options.fromMobx; 1131 | assert(isObject$1(mapModels), "fromMobx should be a object not " + (typeof mapModels === 'undefined' ? 'undefined' : _typeof(mapModels))); 1132 | var _data = typeof this.$options.data === 'function' && this.$options.data() || {}; 1133 | var _computed = this.$options.computed || {}; 1134 | var _methods = this.$options.methods || {}; 1135 | var validModels = getValidModel(mapModels); 1136 | var validActions = getValidAction(validModels, _methods); 1137 | this.$options.methods = __assign({}, _methods, validActions); 1138 | var computedProps = createComputedProps(validModels, _data, _computed, this); 1139 | this.$options.computed = __assign({}, _computed, computedProps); 1140 | this.$toJS = config.toJS; 1141 | this.$isObservable = config.isObservable; 1142 | if (config.observable && typeof config.observable === 'function') { 1143 | this.$observable = config.observable; 1144 | } 1145 | } 1146 | } 1147 | }); 1148 | } 1149 | 1150 | var _Vue; 1151 | function install(instance, config) { 1152 | var version = Number(instance.version.split('.')[0]); 1153 | assert(version >= 2, "[vue-mobx] only adapted to Vue 2 or higher, the Vue version used is " + version + ". Upgrade vue version of your project, please."); 1154 | if (install.installed) { 1155 | return; 1156 | } 1157 | install.installed = true; 1158 | _Vue = Vue; 1159 | assert(!!config, "missed config parameter, here is the doc: https://github.com/dwqs/vue-mobx"); 1160 | assert(config.hasOwnProperty('toJS') && typeof config.toJS === 'function', "missed config#toJS parameter, here is the doc: https://github.com/dwqs/vue-mobx"); 1161 | assert(config.hasOwnProperty('isObservable') && typeof config.isObservable === 'function', "missed config#isObservable parameter, here is the doc: https://github.com/dwqs/vue-mobx"); 1162 | Options.saveOptions(config); 1163 | applyMixin(config); 1164 | } 1165 | if (typeof window !== 'undefined' && window.Vue && window.mobx) { 1166 | install(window.Vue, { 1167 | isObservable: window.mobx.isObservable, 1168 | toJS: window.mobx.toJS, 1169 | observable: window.mobx.observable 1170 | }); 1171 | } 1172 | 1173 | var VueMobx = { 1174 | install: install 1175 | }; 1176 | 1177 | return VueMobx; 1178 | 1179 | }))); 1180 | -------------------------------------------------------------------------------- /example/app.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import VueRouter from "vue-router"; 3 | import {observable, isObservable, toJS} from 'mobx'; 4 | import VueMobx from '../dist/index'; 5 | 6 | Vue.use(VueRouter); 7 | Vue.use(VueMobx, { 8 | /** 9 | * config is needed. 10 | * you can visit it by this.$observable/this.$isObservable/$toJS in your vue component 11 | */ 12 | toJS: toJS, // must 13 | isObservable: isObservable, //must 14 | observable: observable, //optional 15 | }); 16 | 17 | import App from './app.vue'; 18 | 19 | const Outer = {template: ''}; 20 | 21 | const router = new VueRouter({ 22 | mode: 'history', 23 | routes: [ 24 | { path: '/index', component: App } 25 | ] 26 | }); 27 | 28 | const app = new Vue({ 29 | router, 30 | ...Outer 31 | }); 32 | 33 | app.$mount('#test'); -------------------------------------------------------------------------------- /example/models/test.js: -------------------------------------------------------------------------------- 1 | import {observable, action} from 'mobx'; 2 | 3 | class Test { 4 | @observable 5 | count = 0; // only observable property will be merge into vue component's data 6 | count2 = 1; // not will be merge into vue component's data 7 | @observable 8 | numbers = []; // ObservableArray 9 | @observable 10 | info = { 11 | // ObservableObject 12 | name: 'test' 13 | } 14 | 15 | /** 16 | * only the method used @action decorator will be merge into vue component's methods 17 | */ 18 | @action 19 | changeCount(){ 20 | ++this.count; 21 | this.info = Object.assign({}, this.info, { 22 | count: this.count 23 | }); 24 | this.numbers = [].concat(observable(this.numbers).slice(), this.count); 25 | } 26 | 27 | // changeCount2 not will be merge into vue component's methods 28 | changeCount2(){ 29 | ++this.count2; 30 | } 31 | 32 | @action 33 | deleteTodo(index){ 34 | let v = Promise.resolve('deleteTodo'); 35 | let list = observable(this.numbers).slice(); 36 | list.splice(index, 1); 37 | this.deleteTodo = list; 38 | } 39 | } 40 | 41 | const test = new Test(); 42 | export default test 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-mobx", 3 | "version": "2.0.0", 4 | "author": "pomysky@gmail.com", 5 | "description": "Mobx binding for Vuejs 2", 6 | "license": "MIT", 7 | "main": "dist/index.js", 8 | "typings": "types/index.d.ts", 9 | "private": false, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/dwqs/vue-mobx" 13 | }, 14 | "keywords": [ 15 | "vuejs", 16 | "vue", 17 | "mobx" 18 | ], 19 | "scripts": { 20 | "test": "./node_modules/.bin/ava ./test/index.js", 21 | "clean": "rm -rf dist types", 22 | "prepush": "npm run lint", 23 | "prebuild": "npm run prepush && npx tsc -p ./tsconfig.json", 24 | "build": "npx rollup -c", 25 | "build:ug": "npx rollup -c && npx rollup -c rollup.build.config.js", 26 | "lint": "npx tslint -p ./tsconfig.json --type-check src/**/*.ts", 27 | "fix": "npx tslint -p ./tsconfig.json --type-check --fix src/**/*.ts" 28 | }, 29 | "ava": { 30 | "babel": { 31 | "presets": [ 32 | "es2015", 33 | "stage-0" 34 | ], 35 | "plugins": [ 36 | "transform-runtime", 37 | "transform-decorators-legacy" 38 | ] 39 | } 40 | }, 41 | "dependencies": {}, 42 | "peerDependencies": { 43 | "vue": ">=2.0.0", 44 | "mobx": ">=2.2.0" 45 | }, 46 | "devDependencies": { 47 | "@types/node": "^8.0.17", 48 | "ava": "^0.21.0", 49 | "babel-core": "^6.25.0", 50 | "babel-plugin-transform-decorators-legacy": "^1.3.4", 51 | "babel-plugin-transform-runtime": "^6.23.0", 52 | "babel-preset-es2015": "^6.24.1", 53 | "babel-preset-stage-0": "^6.24.1", 54 | "debug": "^2.6.8", 55 | "husky": "^0.14.2", 56 | "mobx": "^3.2.2", 57 | "rollup": "^0.43.0", 58 | "rollup-plugin-babel": "^2.7.1", 59 | "rollup-plugin-commonjs": "^8.0.2", 60 | "rollup-plugin-node-builtins": "^2.1.2", 61 | "rollup-plugin-node-resolve": "^3.0.0", 62 | "rollup-plugin-typescript": "^0.8.1", 63 | "rollup-plugin-uglify": "^2.0.1", 64 | "tslint": "^5.4.3", 65 | "typescript": "^2.4.1", 66 | "uglify-es": "^3.0.26", 67 | "vue": "^2.4.2" 68 | }, 69 | "homepage": "https://github.com/dwqs/vue-mobx", 70 | "bugs": { 71 | "url": "https://github.com/dwqs/vue-mobx/issues" 72 | }, 73 | "engines": { 74 | "node": ">= 6.0.0", 75 | "npm": ">= 5.2.0" 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /rollup.build.config.js: -------------------------------------------------------------------------------- 1 | import uglify from 'rollup-plugin-uglify'; 2 | import { minify } from 'uglify-es'; 3 | 4 | import config from './rollup.config'; 5 | 6 | config.plugins.push( 7 | uglify({ 8 | compress: { 9 | warnings: false, 10 | drop_debugger: true, 11 | drop_console: true 12 | }, 13 | mangle: true 14 | }, minify) 15 | ); 16 | 17 | export default { 18 | entry: 'src/index.ts', 19 | format: 'umd', 20 | moduleName: 'VueMobx', 21 | dest: 'dist/index.min.js', 22 | plugins: config.plugins 23 | }; -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import commonjs from 'rollup-plugin-commonjs'; 2 | import resolve from 'rollup-plugin-node-resolve'; 3 | import typescript from 'rollup-plugin-typescript'; 4 | import babel from 'rollup-plugin-babel'; 5 | import builtins from 'rollup-plugin-node-builtins'; 6 | 7 | export default { 8 | entry: 'src/index.ts', 9 | format: 'umd', 10 | moduleName: 'VueMobx', 11 | dest: 'dist/index.js', 12 | external: ['vue'], 13 | plugins: [ 14 | builtins(), 15 | resolve({ 16 | customResolveOptions: 'node_modules', 17 | jsnext: true 18 | }), 19 | commonjs({ 20 | // https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports 21 | namedExports: { 22 | 23 | } 24 | }), 25 | typescript({ 26 | typescript: require('typescript') 27 | }), 28 | babel({ 29 | exclude: 'node_modules/**', 30 | externalHelpers: false, 31 | runtimeHelpers: true 32 | }) 33 | ] 34 | } -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable-next-line:no-unused-variable 2 | import Vue, {PluginObject} from 'vue'; 3 | 4 | // tslint:disable-next-line:no-unused-variable 5 | import { install } from './install'; 6 | import { Config } from './options'; 7 | 8 | const VueMobx: PluginObject = { 9 | install, 10 | } 11 | 12 | export default VueMobx; 13 | 14 | if (typeof window !== 'undefined' && (window as any).Vue && (window as any).mobx) { 15 | (window as any).Vue.use(VueMobx, { 16 | isObservable: (window as any).mobx.isObservable, 17 | toJS: (window as any).mobx.toJS, 18 | observable: (window as any).mobx.observable, 19 | }) 20 | } 21 | -------------------------------------------------------------------------------- /src/install.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | 3 | import applyMixin from './mixin'; 4 | import { assert } from './utils'; 5 | import { Config, Options } from './options' 6 | 7 | // tslint:disable-next-line:variable-name 8 | export let _Vue: typeof Vue; 9 | 10 | export const install: any = (instance: typeof Vue, config: Config) => { 11 | const version = Number((instance as any).version.split('.')[0]); 12 | assert(version >= 2, `[vue-mobx] only adapted to Vue 2 or higher, the Vue version used is ${version}. Upgrade vue version of your project, please.`); 13 | 14 | if ((install as any).installed) { 15 | return; 16 | } 17 | (install as any).installed = true; 18 | 19 | _Vue = Vue; 20 | 21 | assert( 22 | !!config, 23 | `missed config parameter, here is the doc: https://github.com/dwqs/vue-mobx`, 24 | ); 25 | 26 | assert( 27 | config.hasOwnProperty('toJS') && typeof config.toJS === 'function', 28 | `missed config#toJS parameter, here is the doc: https://github.com/dwqs/vue-mobx`, 29 | ); 30 | 31 | assert( 32 | config.hasOwnProperty('isObservable') && typeof config.isObservable === 'function', 33 | `missed config#isObservable parameter, here is the doc: https://github.com/dwqs/vue-mobx`, 34 | ); 35 | 36 | Options.saveOptions(config); 37 | applyMixin(config); 38 | } 39 | -------------------------------------------------------------------------------- /src/mixin.ts: -------------------------------------------------------------------------------- 1 | import { _Vue } from './install'; 2 | 3 | import { Config } from './options'; 4 | import { 5 | assert, isObject, 6 | getValidModel, getValidAction, 7 | createComputedProps, 8 | } from './utils'; 9 | 10 | // components hooks 11 | // tslint:disable-next-line:no-unused-variable 12 | const $internalHooks = [ 13 | 'beforeMount', 14 | 'mounted', 15 | 'beforeDestroy', 16 | 'destroyed', 17 | 'beforeUpdate', 18 | 'updated', 19 | 'beforeRouteEnter', 20 | 'beforeRouteLeave', 21 | ]; 22 | 23 | // components resources 24 | // tslint:disable-next-line:no-unused-variable 25 | const $internalResources = [ 26 | 'filters', 27 | 'directives', 28 | 'components', 29 | 'computed', 30 | ]; 31 | 32 | export default function applyMixin(config: Config): void { 33 | assert((_Vue as any), `must call Vue.use(VueMobx) to init vue-mobx config.`); 34 | 35 | _Vue.mixin({ 36 | beforeCreate() { 37 | if ((this.$options as any).fromMobx) { 38 | const mapModels = (this.$options as any).fromMobx; 39 | assert(isObject(mapModels), `fromMobx should be a object not ${typeof mapModels}`); 40 | 41 | // tslint:disable-next-line:variable-name 42 | const _data = (typeof this.$options.data === 'function' && (this.$options as any).data()) || {}; 43 | // tslint:disable-next-line:variable-name 44 | const _computed = this.$options.computed || {}; 45 | // tslint:disable-next-line:variable-name 46 | const _methods = this.$options.methods || {}; 47 | 48 | const validModels: object = getValidModel(mapModels); 49 | const validActions: object = getValidAction(validModels, _methods); 50 | 51 | this.$options.methods = { 52 | ..._methods, 53 | ...validActions, 54 | }; 55 | 56 | const computedProps = createComputedProps(validModels, _data, _computed, this); 57 | 58 | this.$options.computed = { 59 | ..._computed, 60 | ...computedProps, 61 | }; 62 | 63 | (this as any).$toJS = config.toJS; 64 | (this as any).$isObservable = config.isObservable; 65 | if (config.observable && typeof config.observable === 'function') { 66 | (this as any).$observable = config.observable; 67 | } 68 | } 69 | }, 70 | }); 71 | } -------------------------------------------------------------------------------- /src/options.ts: -------------------------------------------------------------------------------- 1 | import {IObservableFactory, IObservableFactories} from 'mobx'; 2 | 3 | export type isObservable = (value: any, property?: string) => boolean; 4 | export type observable = IObservableFactory & IObservableFactories & { 5 | deep: { 6 | struct(initialValue?: T): T; 7 | }; 8 | ref: { 9 | struct(initialValue?: T): T; 10 | }; 11 | }; 12 | 13 | export type toJST = (source: T, detectCycles?: boolean) => T 14 | export type toJSAny = (source: any, detectCycles?: boolean) => any 15 | export type toJSArr = (source: any, detectCycles: boolean, alreadySeen: Array<[any, any]>) => any 16 | 17 | export interface Config { 18 | toJS: toJST | toJSAny | toJSArr, 19 | isObservable: isObservable, 20 | observable?: observable 21 | } 22 | 23 | export class Options { 24 | public static options: Config; 25 | 26 | public static saveOptions(config: Config): void { 27 | Options.options = config; 28 | } 29 | } -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | import { _Vue } from './install'; 2 | import { Options } from './options'; 3 | 4 | export function isObject(data: any): boolean { 5 | return data !== null && typeof data === 'object'; 6 | } 7 | 8 | export function assert(condition: boolean, msg: string): void { 9 | if (!condition) { 10 | throw new Error(`[vue-mobx]: ${msg}`); 11 | } 12 | } 13 | 14 | const $mobx: string = '__mobxDidRunLazyInitializers'; 15 | const $$mobx: string = '$mobx'; 16 | 17 | function getProto(obj: object): object { 18 | return Object.getPrototypeOf(obj); 19 | } 20 | 21 | function getOwnProps(obj: object): string[] { 22 | // ES6 class methods aren't enumerable, can't use Object.keys 23 | return Object.getOwnPropertyNames(obj); 24 | } 25 | 26 | export function getValidModel(models: object): object { 27 | const res = {}; 28 | 29 | Object.keys(models).forEach((key) => { 30 | // support typescript 31 | if (Options.options.isObservable(models[key])) { 32 | res[key] = models[key] 33 | } 34 | }); 35 | 36 | return res; 37 | } 38 | 39 | export function getValidAction(models: object, methods: object): object { 40 | const res = {}; 41 | 42 | Object.keys(models).forEach((key) => { 43 | const props: string[] = getOwnProps(getProto(models[key])); 44 | for (let i = 0, l = props.length; i < l; i++) { 45 | if (typeof models[key][props[i]] === 'function' && models[key][props[i]].isMobxAction) { 46 | assert(!methods[props[i]], `The "${props[i]}" method is already defined in methods.`); 47 | res[props[i]] = models[key][props[i]].bind(models[key]); 48 | } 49 | } 50 | }); 51 | 52 | return res; 53 | } 54 | 55 | export function getMobxData(models: object): object { 56 | const res = {}; 57 | 58 | Object.keys(models).forEach((key) => { 59 | const props: string[] = getOwnProps(getProto(models[key])); 60 | // res = (Object as any).assign({}, res, { 61 | // ...models[key].$mobx.values, 62 | // }) 63 | for (let i = 0, l = props.length; i < l; i++) { 64 | if (props[i] !== 'constructor' && props[i] !== $mobx && typeof models[key][props[i]] !== 'function') { 65 | res[props[i]] = models[key][props[i]]; 66 | } 67 | } 68 | }); 69 | 70 | return res; 71 | } 72 | 73 | export function createComputedProps(models: object, data: object, computed: object, vm: any): object { 74 | const res = {}; 75 | 76 | Object.keys(models).forEach((key) => { 77 | const model = models[key]; 78 | const props = getOwnProps(getProto(model)); 79 | 80 | for (let i = 0, l = props.length; i < l; i++) { 81 | if (props[i] !== $mobx && props[i] !== $$mobx && props[i] !== 'constructor' && typeof model[props[i]] !== 'function') { 82 | assert(!(props[i] in data), `The computed property "${props[i]}" is already defined in data.`); 83 | assert(!(props[i] in computed), `The computed property "${props[i]}" is already defined in computed.`); 84 | 85 | const property = Object.getOwnPropertyDescriptor(model, props[i]); 86 | (_Vue as any).util.defineReactive(model, props[i], null, null, true); 87 | 88 | res[props[i]] = { 89 | get() { 90 | return model[props[i]]; 91 | }, 92 | 93 | set(val: any) { 94 | (property as any).set.call(vm, val); 95 | }, 96 | }; 97 | } 98 | } 99 | }); 100 | 101 | return res; 102 | } -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import {observable, isObservable, action, isAction, toJS} from 'mobx'; 3 | import Vue from 'vue'; 4 | import VueMobx from '../dist/index'; 5 | 6 | Vue.use(VueMobx, { 7 | // must 8 | toJS, 9 | // must 10 | isObservable, 11 | // optional 12 | observable, 13 | }); 14 | 15 | class TestModel{ 16 | @observable 17 | name = 'vue-mobx'; 18 | count = 3; 19 | @observable 20 | info = { 21 | project: 'vue-mobx' 22 | } 23 | 24 | @action 25 | changeName(){ 26 | this.name = 'mobx-vue'; 27 | } 28 | 29 | changeCount(){ 30 | this.count = 2; 31 | } 32 | 33 | @action 34 | async actionTest () { 35 | const v = await Promise.resolve('async action'); 36 | this.name = v; 37 | } 38 | } 39 | 40 | test('fromMobx must be a object', (t) => { 41 | t.plan(4); 42 | const error = t.throws(() => { 43 | new Vue({ 44 | template: '
parameter test
', 45 | fromMobx: 'test' 46 | }) 47 | }, Error); 48 | 49 | const error2 = t.throws(() => { 50 | new Vue({ 51 | template: '
parameter test
', 52 | fromMobx: 3 53 | }) 54 | }, Error); 55 | 56 | t.true(error.message.includes('string')); 57 | t.true(error2.message.includes('number')); 58 | }); 59 | 60 | test('same property will throw error', (t) => { 61 | t.plan(4); 62 | 63 | let testModel = new TestModel(); 64 | 65 | const error = t.throws(() => { 66 | new Vue({ 67 | template: '
same property will throw error
', 68 | data: { 69 | name: 'hello' 70 | }, 71 | fromMobx: { 72 | testModel 73 | } 74 | }) 75 | }, Error); 76 | 77 | const error2 = t.throws(() => { 78 | new Vue({ 79 | template: '
same property will throw error
', 80 | data: { 81 | n: 'hello' 82 | }, 83 | computed: { 84 | name () { 85 | return 'error'; 86 | } 87 | }, 88 | fromMobx: { 89 | testModel 90 | } 91 | }) 92 | }, Error); 93 | 94 | t.true(error.message.includes('already defined in data')); 95 | t.true(error2.message.includes('already defined in computed')); 96 | }); 97 | 98 | test('property which is not obserable will not be merged', (t) => { 99 | t.plan(4); 100 | 101 | let testModel = new TestModel(); 102 | 103 | const vm = new Vue({ 104 | template: '
same property will throw error
', 105 | fromMobx: { 106 | testModel 107 | } 108 | }) 109 | 110 | t.true(vm.name === 'vue-mobx'); 111 | t.true(vm.hasOwnProperty('changeName')); 112 | t.false(vm.hasOwnProperty('count')); 113 | t.false(vm.hasOwnProperty('changeCount')); 114 | }); 115 | 116 | class Model2 { 117 | test = '111'; 118 | } 119 | 120 | test('test methods and data change', (t) => { 121 | t.plan(8); 122 | 123 | let testModel = new TestModel(); 124 | 125 | const vm = new Vue({ 126 | template: '
same property will throw error
', 127 | data(){ 128 | return { 129 | message: 'hello' 130 | } 131 | }, 132 | 133 | fromMobx: { 134 | testModel 135 | } 136 | }); 137 | 138 | t.is(vm.info.project, 'vue-mobx') 139 | t.is(typeof vm.$observable, 'function'); 140 | t.is(typeof vm.$isObservable, 'function'); 141 | t.is(typeof vm.$toJS, 'function'); 142 | 143 | t.true(vm.$isObservable(testModel)); 144 | t.false(vm.$isObservable(new Model2())); 145 | t.deepEqual({ project: 'vue-mobx' }, vm.$toJS(vm.info)); 146 | 147 | // call method 148 | vm.changeName(); 149 | 150 | t.is(vm.name, 'mobx-vue'); 151 | }); 152 | 153 | test('test async action', async (t) => { 154 | t.plan(4); 155 | 156 | let testModel = new TestModel(); 157 | 158 | const vm = new Vue({ 159 | template: '
vm1
', 160 | fromMobx: { 161 | testModel 162 | } 163 | }); 164 | 165 | const vm2 = new Vue({ 166 | template: '
vm2
', 167 | fromMobx: { 168 | testModel 169 | } 170 | }); 171 | 172 | t.is(vm.name, 'vue-mobx'); 173 | t.is(vm2.name, 'vue-mobx'); 174 | 175 | await vm.actionTest(); 176 | 177 | t.is(vm.name, 'async action'); 178 | t.is(vm2.name, 'async action'); 179 | }); -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "rootDir": "src", 7 | "outDir": "lib", 8 | "declaration": true, 9 | "declarationDir": "types", 10 | "types": [ 11 | "node" 12 | ], 13 | "strict": true, 14 | "isolatedModules": false, 15 | "experimentalDecorators": true, 16 | "noImplicitAny": true, 17 | "noImplicitReturns": true, 18 | "removeComments": true, 19 | "suppressImplicitAnyIndexErrors": true, 20 | "allowSyntheticDefaultImports": true, 21 | "allowUnreachableCode": true, 22 | "allowUnusedLabels": true 23 | }, 24 | "include": [ 25 | "src/**/*.ts" 26 | ], 27 | "compileOnSave": false 28 | } 29 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "enable": true, 4 | "jsEnable": true, 5 | "rules": { 6 | "max-line-length": [true, 200], 7 | "indent": [true, "indent", 4], 8 | "interface-name": [true, "never-prefix"], 9 | "jsdoc-format": false, 10 | "no-consecutive-blank-lines": false, 11 | "no-console": [false], 12 | "no-duplicate-variable": true, 13 | "semicolon": ["always"], 14 | "triple-equals": [true, "allow-null-check"], 15 | "comment-format": [true, "check-space"], 16 | "no-trailing-whitespace": false, 17 | "align": [false], 18 | "eofline": false, 19 | "max-classes-per-file": [true, 5], 20 | "no-unused-variable": true, 21 | "quotemark": [true, "single", "avoid-escape"], 22 | "object-literal-sort-keys":false, 23 | "ordered-imports": [false], 24 | "no-string-literal": false 25 | }, 26 | "jsRules": { 27 | "max-line-length": [true, 120], 28 | "indent": [true, "indent", 4], 29 | "comment-format": [true, "check-space"], 30 | "no-console": [false], 31 | "no-duplicate-variable": true, 32 | "semicolon": ["always"], 33 | "triple-equals": [true, "allow-null-check"], 34 | "jsdoc-format": false, 35 | "no-trailing-whitespace": false, 36 | "align": [false], 37 | "eofline": false, 38 | "max-classes-per-file": [true, 5], 39 | "no-unused-variable": true, 40 | "quotemark": [true, "single", "avoid-escape"], 41 | "object-literal-sort-keys":false 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /types/connect.d.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | export declare function connect(mapModels: object): (vueComponent: C) => C; 3 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { PluginObject } from 'vue'; 2 | import { Config } from './options'; 3 | declare const VueMobx: PluginObject; 4 | export default VueMobx; 5 | -------------------------------------------------------------------------------- /types/install.d.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import { Config } from './options'; 3 | export declare let _Vue: typeof Vue; 4 | export declare function install(instance: typeof Vue, config: Config): void; 5 | -------------------------------------------------------------------------------- /types/mixin.d.ts: -------------------------------------------------------------------------------- 1 | import { Config } from './options'; 2 | export default function applyMixin(config: Config): void; 3 | -------------------------------------------------------------------------------- /types/options.d.ts: -------------------------------------------------------------------------------- 1 | import { IObservableFactory, IObservableFactories } from 'mobx'; 2 | export declare type isObservable = (value: any, property?: string) => boolean; 3 | export declare type observable = IObservableFactory & IObservableFactories & { 4 | deep: { 5 | struct(initialValue?: T): T; 6 | }; 7 | ref: { 8 | struct(initialValue?: T): T; 9 | }; 10 | }; 11 | export declare type toJST = (source: T, detectCycles?: boolean) => T; 12 | export declare type toJSAny = (source: any, detectCycles?: boolean) => any; 13 | export declare type toJSArr = (source: any, detectCycles: boolean, alreadySeen: Array<[any, any]>) => any; 14 | export interface Config { 15 | toJS: toJST | toJSAny | toJSArr; 16 | isObservable: isObservable; 17 | observable?: observable; 18 | } 19 | export declare class Options { 20 | static options: Config; 21 | static saveOptions(config: Config): void; 22 | } 23 | -------------------------------------------------------------------------------- /types/utils.d.ts: -------------------------------------------------------------------------------- 1 | export declare function isObject(data: any): boolean; 2 | export declare function assert(condition: boolean, msg: string): void; 3 | export declare function getValidModel(models: object): object; 4 | export declare function getValidAction(models: object, methods: object): object; 5 | export declare function getMobxData(models: object): object; 6 | export declare function createComputedProps(models: object, data: object, computed: object, vm: any): object; 7 | --------------------------------------------------------------------------------