UNPKG

pinia-class-component

Version:

ECMAScript / TypeScript decorator for class-style Pinia store.

6 lines 1.47 kB
/** * pinia-class-component v0.9.4 * (c) 2022-present PentaTea * @license MIT */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("pinia")):"function"==typeof define&&define.amd?define(["exports","pinia"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).PiniaClassComponent={},e.Pinia)}(this,function(e,t){"use strict";var n=[];function o(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o.name=o.name||o.id||e.name,o.state||(o.state={}),o.actions||(o.actions={}),o.getters||(o.getters={});var r=e.prototype;Object.getOwnPropertyNames(r).forEach(function(e){if("constructor"!==e)if(n.indexOf(e)>-1)o[e]=r[e];else{var t=Object.getOwnPropertyDescriptor(r,e);void 0!==t.value?"function"==typeof t.value?o.actions[e]=t.value:o.state[e]=t.value:t.get&&(o.getters[e]=t.get)}});var i=new e;Object.keys(i).forEach(function(e){o.state[e]=i[e]});var a=e.__decorators__;a&&(a.forEach(function(e){return e(o)}),delete e.__decorators__);var c=o.state;o.state=function(){return c};var u=t.defineStore(o.name,o);return function(){return u()}}e.Pinia=function(){},e.Store=function(e){return"function"==typeof e?o(e):function(t){return o(t,e)}},e.createDecorator=function(e){return function(t,n,o){var r="function"==typeof t?t:t.constructor;r.__decorators__||(r.__decorators__=[]),"number"!=typeof o&&(o=void 0),r.__decorators__.push(function(t){return e(t,n,o)})}},Object.defineProperty(e,"__esModule",{value:!0})});