项目作者: Obooman

项目描述 :
redux connector for ractive.js application, with @rematch as redux api provider.
高级语言: JavaScript
项目地址: git://github.com/Obooman/ractive-rematch.git
创建时间: 2020-01-30T10:20:26Z
项目社区:https://github.com/Obooman/ractive-rematch

开源协议:MIT License

下载


" class="reference-link">ractive-rematch CI Test & Build Badge

Redux connector for ractivejs application, with rematch as redux api provider.

Get Started

Install dependencies

  1. $ yarn add @rematch/core ractive-rematach

Initialize store binding

  1. import Ractive from "ractive";
  2. import { init } from "@rematch/core";
  3. import { bindStore } from "ractive-rematch";
  4. import models from "./models";
  5. bindStore(init({ models }));
  6. const applicationContainerDOMElement = document.querySelector("#root");
  7. const instance = new Ractive({
  8. el: applicationContainerDOMElement,
  9. template: `<span>{variable}</span>`,
  10. data: {
  11. variable: 12
  12. }
  13. });
  14. const Component = Ractive.extend({
  15. data: {
  16. variable: 13
  17. }
  18. });
  19. const mapStateToData = state => ({
  20. name: state.userInfo.name,
  21. age: state.userInfo.age
  22. });
  23. const mapDispatchToMethod = dispatch => ({
  24. changeName(name) {
  25. dispatch.userInfo.changeName(name);
  26. }
  27. });
  28. /*
  29. * the dispatch function will be attached to instance.
  30. */
  31. export const connectedInstance = connectInstance(
  32. mapStateToData,
  33. mapDispatchToMethod
  34. )(instance);
  35. // Connect state to a subclass instead of instance please use `connect`
  36. export const connectedComponent = connect(
  37. mapStateToData,
  38. mapDispatchToMethod
  39. )(Component);