Skip to content

Commit 33367a0

Browse files
committed
Initial commit
0 parents  commit 33367a0

File tree

13 files changed

+7830
-0
lines changed

13 files changed

+7830
-0
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# https://docs.github.com/en/actions/guides/building-and-testing-nodejs
2+
3+
name: CI
4+
on:
5+
push:
6+
paths-ignore: ['*.md']
7+
jobs:
8+
test:
9+
strategy:
10+
matrix:
11+
include:
12+
- { node-version: 12.x, platform: ubuntu-latest }
13+
- { node-version: 14.x, platform: windows-latest }
14+
- { node-version: 16.x, platform: macos-latest }
15+
runs-on: ${{ matrix.platform }}
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: actions/setup-node@v2
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
cache: npm
22+
- run: npm ci
23+
- run: npm test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
node_modules/
3+
_*

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2021 Adam Sołtysik
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
vue-component-store
2+
===================
3+
4+
[![License](https://img.shields.io/github/license/adamsol/vue-component-store.svg)](https://github.com/adamsol/vue-component-store/blob/master/LICENSE.txt)
5+
[![CI](https://github.com/adamsol/vue-component-store/actions/workflows/ci.yml/badge.svg)](https://github.com/adamsol/vue-component-store/actions)
6+
7+
A simple plugin for Vue.js 2.6.x, offering a clean way to keep the state of your application inside your components.
8+
9+
This library was inspired by https://github.com/LinusBorg/vue-reactive-provide. The basic idea is similar, but the API and implementation are different.
10+
11+
Why?
12+
----
13+
14+
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.
15+
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).
16+
17+
API
18+
---
19+
20+
You can use the following new options in your components:
21+
22+
* `provideFields` – A list of fields (from `props`, `data`, or `computed`) to share with the descendant components. The fields will be reactive (one-way binding, like props).
23+
* `injectFields` – A list of fields (provided by ancestor components) to use in the current component. The effect is similar to using `mapState` and `mapGetters` from Vuex.
24+
* `provideMethods` – A list of methods to share with the descendant components.
25+
* `injectMethods` – A list of methods (provided by ancestor components) to use in the current component. This is functionally equivalent to bare `inject`, but exists for consistency of the API. The effect is similar to using `mapActions` from Vuex.
26+
27+
In order to share global state between all components in your application, use `provideFields`/`provideMethods` in the root component.
28+
29+
Example
30+
-------
31+
32+
See https://github.com/adamsol/vue-component-store/tree/master/test/components/.

babel.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
const mode = process.env.NODE_ENV;
3+
4+
module.exports = {
5+
presets: [
6+
['@babel/preset-env', {
7+
targets: mode === 'test' ? { node: 'current' } : 'defaults',
8+
}],
9+
],
10+
};

jest.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
module.exports = {
3+
moduleFileExtensions: ['js', 'vue'],
4+
testEnvironment: 'jsdom',
5+
testMatch: ['**/test/**/*.js'],
6+
transform: {
7+
'^.+\\.js$': 'babel-jest',
8+
'^.+\\.vue$': 'vue-jest',
9+
},
10+
};

0 commit comments

Comments
 (0)