Skip to content

Commit e565732

Browse files
committed
add CHANGELOG, README, LICENSE, .npmignore and eslint
1 parent abe7060 commit e565732

9 files changed

+640
-109
lines changed

.npmignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.editorconfig
2+
3+
npm-debug.log
4+
yarn-error.log
5+
yarn.lock
6+
7+
*.spec.js
8+
.travis.yml
9+
10+
node_modules/
11+
example/
12+
coverage/
13+
.cache/
14+
dist/

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Change Log
2+
This project adheres to [Semantic Versioning](http://semver.org/).
3+
4+
## 0.1.0
5+
* Add `README.md`.
6+
* Add `CHANGELOG.md`.
7+
* Add `LICENSE`.
8+
* Add `.npmignore`.
9+
* Add `eslint`.
10+
11+
## 0.0.1
12+
* Initial release.

LICENSE

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

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# storeon-svelte
2+
3+
<img src="https://storeon.github.io/storeon/logo.svg" align="right"
4+
alt="Storeon logo by Anton Lovchikov" width="160" height="142">
5+
6+
A tiny (only 128 bytes) connector for **[Storeon]** and Svelte.
7+
8+
---------------------
9+
[Storeon]: https://github.com/storeon/storeon
10+
11+
## How to use
12+
```javascript
13+
import createStore from 'storeon';
14+
import { bindStoreon } from 'storeon-svelte';
15+
16+
let counter = store => {
17+
// Initial state
18+
store.on('@init', () => ({ count: 0 }));
19+
// Reducers returns only changed part of the state
20+
store.on('inc', ({ count }) => ({ count: count + 1 }));
21+
};
22+
23+
const store = createStore([counter]);
24+
25+
export const connect = bindStoreon(store);
26+
```
27+
28+
```html
29+
<script>
30+
import { connect } from './store.js';
31+
32+
const [dispatch, count] = connect('count');
33+
34+
function increment() {
35+
dispatch('inc');
36+
}
37+
</script>
38+
39+
<h1>The count is {$count}</h1>
40+
41+
<button on:click={increment}>
42+
+
43+
</button>
44+
```

index.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@
44
*
55
* @return {}
66
*/
7-
const bindStoreon = function (store) {
7+
function bindStoreon (store) {
88
/**
99
*
1010
*/
1111
return function (key) {
12-
var state = store.get();
13-
var subscribers = [];
12+
var state = store.get()
13+
var subscribers = []
1414

15-
function subscribe(run) {
16-
subscribers.push(run);
15+
function subscribe (run) {
16+
subscribers.push(run)
1717
run(state[key])
1818

1919
return function () {
20-
var index = subscribers.indexOf(run);
21-
if (index !== -1) subscribers.splice(index, 1);
20+
var index = subscribers.indexOf(run)
21+
if (index !== -1) subscribers.splice(index, 1)
2222
}
2323
}
2424

25-
store.on("@changed", function (_, changed) {
25+
store.on('@changed', function (_, changed) {
2626
if (key in changed) {
27-
subscribers.forEach(s => s(changed[key]))
27+
subscribers.forEach(function (s) { return s(changed[key]) })
2828
}
2929
})
3030

3131
var changes = {
3232
subscribe: subscribe
3333
}
3434

35-
return [store.dispatch, changes];
35+
return [store.dispatch, changes]
3636
}
3737
}
3838

39-
module.exports = { bindStoreon }
39+
module.exports = { bindStoreon: bindStoreon }

index.spec.js

-74
This file was deleted.

index.test.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
var createStore = require('storeon')
2+
3+
var bindStoreon = require('.').bindStoreon
4+
5+
function connectFactory () {
6+
function counter (store) {
7+
store.on('@init', function () { return { count: 0, foo: 'baz' } })
8+
store.on('inc', function (state) { return { count: state.count + 1 } })
9+
}
10+
11+
var store = createStore([counter])
12+
13+
return bindStoreon(store)
14+
}
15+
16+
it('should start with init value', function () {
17+
var connect = connectFactory()
18+
19+
var count = connect('count')[1]
20+
21+
count.subscribe(function (value) { return expect(value).toBe(0) })
22+
})
23+
24+
it('should be reactive', function () {
25+
var connect = connectFactory()
26+
27+
var currentValue
28+
var connection = connect('count')
29+
var dispatch = connection[0]
30+
var count = connection[1]
31+
32+
count.subscribe(function (value) { currentValue = value })
33+
34+
expect(currentValue).toBe(0)
35+
36+
dispatch('inc')
37+
38+
expect(currentValue).toBe(1)
39+
})
40+
41+
it('should not emmit changes on other dispatches', function () {
42+
var connect = connectFactory()
43+
var spyCb = jest.fn()
44+
45+
var connection = connect('foo')
46+
var dispatch = connection[0]
47+
var foo = connection[1]
48+
49+
foo.subscribe(spyCb)
50+
51+
dispatch('inc')
52+
53+
expect(spyCb).toBeCalledWith('baz')
54+
expect(spyCb).toBeCalledTimes(1)
55+
})
56+
57+
it('shoud to be unsubscribed', function () {
58+
var connect = connectFactory()
59+
60+
var currentValue
61+
var connection = connect('count')
62+
var dispatch = connection[0]
63+
var count = connection[1]
64+
65+
var unsubscribe = count.subscribe(function (value) { currentValue = value })
66+
67+
expect(currentValue).toBe(0)
68+
69+
dispatch('inc')
70+
71+
expect(currentValue).toBe(1)
72+
73+
unsubscribe()
74+
unsubscribe()
75+
dispatch('inc')
76+
77+
expect(currentValue).toBe(1)
78+
})

package.json

+19-2
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,37 @@
77
"license": "MIT",
88
"scripts": {
99
"start": "parcel serve example/index.html --open",
10-
"test": "jest --coverage && size-limit"
10+
"lint": "eslint *.js",
11+
"test": "jest --coverage && yarn lint && size-limit"
1112
},
1213
"devDependencies": {
14+
"@logux/eslint-config": "^28.2.1",
15+
"eslint": "^5.16.0",
16+
"eslint-config-standard": "^12.0.0",
17+
"eslint-plugin-es5": "^1.3.1",
18+
"eslint-plugin-import": "^2.17.2",
19+
"eslint-plugin-import-helpers": "^0.1.4",
20+
"eslint-plugin-jest": "^22.5.1",
21+
"eslint-plugin-node": "^9.0.1",
22+
"eslint-plugin-promise": "^4.1.1",
23+
"eslint-plugin-security": "^1.4.0",
24+
"eslint-plugin-standard": "^4.0.0",
1325
"husky": "^2.3.0",
1426
"jest": "^24.8.0",
1527
"lint-staged": "^8.1.7",
1628
"parcel-bundler": "^1.12.3",
1729
"parcel-plugin-svelte": "^3.0.1",
1830
"prettier": "^1.17.1",
1931
"size-limit": "^1.3.2",
20-
"svelte": "^3.4.0"
32+
"svelte": "^3.4.0",
33+
"typescript": "^3.4.5"
2134
},
2235
"dependencies": {
2336
"storeon": "^0.8.3"
2437
},
2538
"lint-staged": {
2639
"*.js": [
40+
"eslint --fix",
2741
"prettier --write",
2842
"git add"
2943
]
@@ -42,6 +56,9 @@
4256
"limit": "128 B"
4357
}
4458
],
59+
"eslintConfig": {
60+
"extends": "@logux/eslint-config/browser"
61+
},
4562
"prettier": {
4663
"trailingComma": "all",
4764
"tabWidth": 2,

0 commit comments

Comments
 (0)