UNPKG

@aimwhy/vue-function-api

Version:

Vue2 plugin for the function-based RFC

12 lines 7.62 kB
/*! * * @aimwhy/vue-function-api v0.0.7 * https://github.com/aimwhy/vue-function-api * * Copyright (c) https://github.com/aimwhy * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ !function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["vue-function-api"]=t():n["vue-function-api"]=t()}(window,function(){return function(n){var t={};function e(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return n[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}return e.m=n,e.c=t,e.d=function(n,t,o){e.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:o})},e.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},e.t=function(n,t){if(1&t&&(n=e(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var o=Object.create(null);if(e.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var r in n)e.d(o,r,function(t){return n[t]}.bind(null,r));return o},e.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(t,"a",t),t},e.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},e.p="",e(e.s=0)}([function(n,t,e){"use strict";e.r(t),e.d(t,"createComponent",function(){return g}),e.d(t,"state",function(){return O}),e.d(t,"value",function(){return _}),e.d(t,"computed",function(){return w}),e.d(t,"onCreated",function(){return S}),e.d(t,"onBeforeMount",function(){return C}),e.d(t,"onMounted",function(){return U}),e.d(t,"onBeforeUpdate",function(){return T}),e.d(t,"onUpdated",function(){return A}),e.d(t,"onActivated",function(){return D}),e.d(t,"onDeactivated",function(){return z}),e.d(t,"onBeforeDestroy",function(){return B}),e.d(t,"onDestroyed",function(){return F}),e.d(t,"onErrorCaptured",function(){return Q}),e.d(t,"onUnmounted",function(){return V}),e.d(t,"watch",function(){return L}),e.d(t,"provide",function(){return N}),e.d(t,"inject",function(){return R}),e.d(t,"plugin",function(){return Y});var o=function(n){return n},r=function(n){return Object.prototype.toString.call(n)},u=function(n){return"[object Array]"===r(n)},i=function(n){return"[object Object]"===r(n)},c=function(n,t){return!!n&&Object.prototype.hasOwnProperty.call(n,t)};function f(n,t){if(!n)throw new Error("[vue-function-api] ".concat(t))}function a(n,t,e){var o=3<arguments.length&&void 0!==arguments[3]?arguments[3]:e;Object.defineProperty(n,e,{enumerable:!0,configurable:!1,get:function(){return t[o]},set:function(n){t[o]=n}})}var s=null;function d(){return f(s,"must call Vue.use(plugin) before using any function."),s}function l(n,t){d().util.warn(n,t)}var p=null;function v(){return p}function y(n){p=n}function b(n){var t=v();return f(t,'"'.concat(n,'" get called outside of "setup()"')),t}function g(n){return"function"==typeof n?{setup:n}:n}function h(n){this.observe=n}function m(n){return n instanceof h}function $(n){if(n)for(var t=Object.keys(n),e=0;e<t.length;e++){var o=t[e],r=n[o];m(r)?a(n,r.observe,o,"$$value"):(i(r)||u(r))&&!c(r,"__ob__")&&(n[o]=$(r))}return n}function j(n){var t=d();if(t.observable)return t.observable(n);var e=t.config.silent;t.config.silent=!0;var o=new t({data:{$$state:n}});return t.config.silent=e,o._data.$$state}function O(n){return j(u(n)||i(n)?$(n):n)}function _(n){return new h(j({$$value:u(n)||i(n)?$(n):n}))}function w(n,t){return new h(function(n){var t=d(),e=t.config.silent;t.config.silent=!0;var o=new t({computed:n});return t.config.silent=e,o}({$$value:{get:n,set:t}}))}Object.defineProperty(h.prototype,"value",{enumerable:!0,configurable:!0,get:function(){return this.observe.$$value},set:function(n){this.observe.$$value=n}});var x=function(n){return"on".concat(n[0].toUpperCase()).concat(n.slice(1))};function k(n){return function(t){b(x(n)).$on("hook:".concat(n),t)}}var P,M,E,S=k("created"),C=k("beforeMount"),U=k("mounted"),T=k("beforeUpdate"),A=k("updated"),D=k("activated"),z=k("deactivated"),B=k("beforeDestroy"),F=k("destroyed"),Q=k("errorCaptured"),V=(P=["destroyed","deactivated"],M="unmounted",function(n){var t=b(x(M));P.forEach(function(e){return t.$on("hook:".concat(e),n)})}),I="vfa.key.preFlushQueue",q="vfa.key.postFlushQueue";function G(n){return function(){H(this,n)}}function H(n,t){for(var e=n[t],o=0;o<e.length;o++)e[o]();e.length=0}function J(n){n.$nextTick(function(){n[I].length&&H(n,I),n[q].length&&H(n,q)})}function K(n,t,e,r){var u=m(t)?function(){return t.observe.$$value}:t,i=o,c=function(n,t){i(),e(n,t,function(n){i=n})},a=function(n,t){return a=s,r.lazy?s(n,t):c(n,t)},s=function(t,e){!function(n,t,e){"pre"===e?(J(n),n[I].push(t)):"post"===e?(J(n),n[q].push(t)):"sync"===e?t():f(!1,'flush must be one of ["post", "pre", "sync"], but got '.concat(e))}(n,function(){return c(t,e)},r.flush)},d=n.$watch(u,a,{immediate:!r.lazy,deep:r.deep,sync:"sync"===r.flush});return function(){i(),d()}}function L(n,t){var e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},r=Object.assign({lazy:!1,deep:!1,flush:"post"},e),i=v();if(!i){if(!E){var c=d(),f=c.config.silent;c.config.silent=!0,E=new c,c.config.silent=f}i=E,r.flush="sync"}return function(n){n[I]||(n[I]=[],n[q]=[],n.$on("hook:beforeUpdate",G(I)),n.$on("hook:updated",G(q)))}(i),(u(n)?function(n,t,e,r){var u=Array(t.length),i=Array(t.length),c=o,f=function(n,t){c(),e(n,t,function(n){c=n})},a=t.map(function(t,e){return function(t,e){return K(n,t,function(n,t){i[e]!==n&&(u[e]=t,i[e]=n,f(i,u))},r)}(t,e)});return function(){c(),a.forEach(function(n){return n()})}}:K)(i,n,t,r)}function N(n){if(n){var t=b("provide");t._provided="function"==typeof n?n.call(t):n}}function R(n){if(n){for(var t=b("inject"),e=t;e;){if(e._provided&&c(e._provided,n))return e._provided[n];e=e.$parent}l('Injection "'.concat(n,'" not found'),t)}}function W(n,t){return s&&s===n?f(!1,"already installed. Vue.use(plugin) should be called only once"):(n.config.optionMergeStrategies.setup=n.config.optionMergeStrategies.data,function(n){s=n}(n),void t(n))}function X(n){n.mixin({created:function(){var n=this,t=n.$options.setup;if(t){if("function"!=typeof t)return l('The "setup" should be a function',n);var e,u=function(n){var t={vm:n};return["props","parent","root","refs","slots","attrs"].forEach(function(e){Object.defineProperty(t,e,{enumerable:!0,configurable:!0,get:function(){return n["$".concat(e)]},set:function(){l('Cannot assign for read-only property "'.concat(e,'"'),n)}})}),["emit"].forEach(function(e){Object.defineProperty(t,e,{enumerable:!0,configurable:!0,get:function(){return function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];n["$".concat(e)].apply(n,t)}},set:o})}),t}(n);y(n);try{e=t(n.$props||{},u)}catch(t){l('there is an error occuring in "setup"',n),console.log(t)}finally{y(null)}return e?"function"==typeof e?n.$options.render=function(){return e(u.props,u.slots,u.attrs)}:i(e)?(Object.keys(e).forEach(function(t){return function(n,t){var e=n.$options.props,o=n.$options.methods,r=n.$options.computed,u='The setup binding property "'.concat(t,'" is already declared'),i=".";c(n.$data,t)?i="as a data.":e&&c(e,t)?i="as a prop.":o&&c(o,t)?i="as a method.":r&&c(r,t)&&(i="as a computed."),"."!==i&&l(u+i,n)}(n,t)}),n._data2=j($(e)),void Object.keys(e).forEach(function(t){return a(n,n._data2,t)})):f(!1,'"setup" must return a "Object", get "'.concat(r(e),'"')):void 0}}})}var Y={install:function(n){return W(n,X)}}}])});