UNPKG

2.42 kBJavaScriptView Raw
1/*!
2 * vue-messenger v2.3.3
3 * (c) 2018-present fjc0k <fjc0kb@gmail.com> (https://github.com/fjc0k)
4 * Released under the MIT License.
5 */
6!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueMessenger=t()}(this,function(){"use strict";var e=function(e){return"function"==typeof e},t=function(e){return e&&"object"==typeof e},n=Object.create(null),i={prop:"value",event:"input"};return{beforeCreate:function(){if(!this.__MessengerBeforeCreate__){this.__MessengerBeforeCreate__=!0;var a=this.$options;a.localDataKeys||(a.localDataKeys=[]),a.methods||(a.methods={}),a.watch||(a.watch={});for(var r=a.model||i,s=a.props||{},o=Object.keys(s),l=function(){var i=o[c],l=s[i];if(Array.isArray(l.enum)){var u=l.validator;l.validator=function(e){return l.enum.indexOf(e)>=0&&(!u||u.apply(this,arguments))},"default"in l||(l.default=l.enum[0])}if(!0===l.numeric){var h=l.validator;l.type=[String,Number],l.validator=function(e){var t=l.infinite,n=l.range;return(t&&(e===1/0||e===-1/0)||function(e){return!isNaN(e-parseFloat(e))}(e))&&(!Array.isArray(n)||e>=n[0]&&e<=n[1])&&(!h||h.apply(this,arguments))}}var f,d=i===r.prop,p=d?r.event:"update:"+i,v=d||!!l.sync,m=!!l.transform,y=l.on&&e(l.on.receive||l.on.change),_=v||m,g=void 0,$=void 0,b=void 0,D=l.on;if((y||_)&&t(D)&&(e(D.receive)&&(g=D.receive),e(D.send)&&($=D.send),e(D.change)&&(b=D.change)),_){var w,A,M=l.transform;e(M)?w=M:t(M)&&(e(M.receive)&&(w=M.receive),e(M.send)&&(A=M.send));var j=((f=i)in n||(n[f]=f.charAt(0).toUpperCase()+f.slice(1)),n[f]),C="local"+j,K="last"+j+"$$",x="lastLocal"+j+"$$",N="send"+j;a.localDataKeys.push(C),a.watch[i]={immediate:!0,handler:function(e,t){e!==t&&e!==this[x]?(!w||null==e||(e=w.call(this,e))!==t&&e!==this[x])&&(g&&!1===g.call(this,e,t)||b&&!1===b.call(this,e,t)||(this[K]=e,this[C]=e)):this[K]=e}},a.watch[C]={immediate:!1,handler:function(e,t){e!==t&&e!==this[K]?(!A||null==e||(e=A.call(this,e))!==t&&e!==this[K])&&($&&!1===$.call(this,e,t)||b&&!1===b.call(this,e,t)||(this[x]=e,v&&this.$emit(p,e,t))):this[x]=e}},v&&(a.methods[N]=function(e){this[C]=e})}else y&&(a.watch[i]={immediate:!0,handler:function(e,t){e!==t&&(g&&g.call(this,e,t),b&&b.call(this,e,t))}})},c=0;c<o.length;c++)l()}},data:function(){if(!this.__MessengerData__)return this.__MessengerData__=!0,this.$options.localDataKeys.reduce(function(e,t){return e[t]=null,e},{})}}});