Skip to content

Commit bb9b5a1

Browse files
committed
Release version 1.0.0
1 parent 33367a0 commit bb9b5a1

File tree

4 files changed

+119
-2
lines changed

4 files changed

+119
-2
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ vue-component-store
33

44
[![License](https://img.shields.io/github/license/adamsol/vue-component-store.svg)](https://github.com/adamsol/vue-component-store/blob/master/LICENSE.txt)
55
[![CI](https://github.com/adamsol/vue-component-store/actions/workflows/ci.yml/badge.svg)](https://github.com/adamsol/vue-component-store/actions)
6+
[![npm](https://img.shields.io/npm/v/vue-component-store.svg)](https://www.npmjs.com/package/vue-component-store)
67

78
A simple plugin for Vue.js 2.6.x, offering a clean way to keep the state of your application inside your components.
89

@@ -14,6 +15,19 @@ Why?
1415
1. Vuex is centralized by design, but suggests dividing the store into modules to mimic the application's structure. This usually requires a lot of boilerplate. It's easier to use the existing component hierarchy and Vue's reactivity system directly instead.
1516
2. Vue has a `provide`/`inject` mechanism for passing data down the component hierarchy without chains of props, but [it's not reactive by default](https://github.com/vuejs/vue/issues/7017).
1617

18+
Installation
19+
------------
20+
21+
```sh
22+
npm install vue-component-store
23+
```
24+
25+
```js
26+
import VueComponentStore from 'vue-component-store';
27+
28+
Vue.use(VueComponentStore);
29+
```
30+
1731
API
1832
---
1933

dist/index.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.default = void 0;
7+
8+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
9+
10+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11+
12+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13+
14+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15+
16+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
17+
18+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
19+
20+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21+
22+
var _default = {
23+
install: function install(Vue) {
24+
Vue.mixin({
25+
beforeCreate: function beforeCreate() {
26+
var _this = this;
27+
28+
// Idea for provide/inject reactivity taken from https://github.com/vuejs/vue/issues/7017#issuecomment-480906691.
29+
// Implementation details for options merging borrowed from https://github.com/LinusBorg/vue-reactive-provide/.
30+
// Note: the merge function for `inject` seems to work only with object-based definitions, even though simple lists with names to inject would suffice here.
31+
var field_getter = function field_getter(name) {
32+
return name + '_$getter';
33+
};
34+
35+
var options = {
36+
provide: [],
37+
inject: [],
38+
computed: []
39+
};
40+
41+
if (this.$options.provideFields) {
42+
options.provide.push(Object.fromEntries(this.$options.provideFields.map(function (name) {
43+
return [field_getter(name), function () {
44+
return _this[name];
45+
}];
46+
})));
47+
}
48+
49+
if (this.$options.injectFields) {
50+
options.inject.push(Object.fromEntries(this.$options.injectFields.map(function (name) {
51+
return [field_getter(name), {
52+
from: field_getter(name)
53+
}];
54+
})));
55+
options.computed.push(Object.fromEntries(this.$options.injectFields.map(function (name) {
56+
return [name, {
57+
get: function get() {
58+
return this[field_getter(name)]();
59+
}
60+
}];
61+
})));
62+
}
63+
64+
if (this.$options.provideMethods) {
65+
options.provide.push(function () {
66+
return Object.fromEntries(_this.$options.provideMethods.map(function (name) {
67+
return [name, _this[name]];
68+
}));
69+
});
70+
}
71+
72+
if (this.$options.injectMethods) {
73+
options.inject.push(Object.fromEntries(this.$options.injectMethods.map(function (name) {
74+
return [name, {
75+
from: name
76+
}];
77+
})));
78+
}
79+
80+
for (var _i = 0, _Object$entries = Object.entries(options); _i < _Object$entries.length; _i++) {
81+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
82+
name = _Object$entries$_i[0],
83+
array = _Object$entries$_i[1];
84+
85+
var _iterator = _createForOfIteratorHelper(array),
86+
_step;
87+
88+
try {
89+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
90+
var option = _step.value;
91+
this.$options[name] = Vue.config.optionMergeStrategies[name](this.$options[name], option);
92+
}
93+
} catch (err) {
94+
_iterator.e(err);
95+
} finally {
96+
_iterator.f();
97+
}
98+
}
99+
}
100+
});
101+
}
102+
};
103+
exports.default = _default;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-component-store",
3-
"version": "0.0.0",
3+
"version": "1.0.0",
44
"keywords": [
55
"vue",
66
"vuex",

0 commit comments

Comments
 (0)