Svelte bindings for Redux. Connect API based on react-redux.
This library let's you use Redux without any constraints or awkward store subscription management. I've recreated the solution from react-redux - the connect API is almost identical.
I'm aware of fact that there's already npm-packages which are trying to accomplish the same goal, but actually I don't think they work as they should be - I tried them and I had to either use the Svelte's store, change API or take care of the store subscription in the body of connected component. This tiny library is the answer to the above problems, and I decided to share my work with everyone.
Basic example below.
// App.svelte<script>;; // redux store;</script><Provider store><Todos /></Provider>// Todos/index.js;;;const selectTodos = statetodos;const selectUndoneTodos =;const addTodo = type: "ADD_TODO" text ;const mapStateToProps =todos:;const mapDispatchToProps =addTodo;mapStateToProps mapDispatchToPropsTodos;// Todos/Todos.svelte<script>let addTodo;let todos;let text = "";</script><input bind:value=text /><button on:click= >add todo</button><ul>#each todos as t<li>t</li>/each</ul>
If you're interested in docs you can rely on https://react-redux.js.org/api/connect#overview
Although there's little difference:
- theres no support for 2 options fields: forwardRef and pure because the author consider them as React specific,
- the implementation consider all components as pure in the context of areStatesEqual, areOwnPropsEqual, areStatePropsEqual, areMergedPropsEqual functions default behavior,
- the counterpart of option options.context is options.store
Feel free to submit any issue or PR.