简体   繁体   English

如何将ngrx存储注入库中

[英]How to inject ngrx store into a library

I'm creating a drag and drop angular module that I hope to externalize and publish to npm. 我正在创建一个拖放角度模块,希望将其外部化并发布到npm。 The library will essentially allow the user to define drag and drop areas and associate ngrx actions with them. 该库实际上将允许用户定义拖放区域并将ngrx动作与它们相关联。

const DND_RULES: DndRule[] = [
   new DndRule('area1', 'area2', MOVE_AREA1_TO_AREA2_ACTION.getAction),
   new DndRule('area2', 'area1', COPY_AREA2_TO_AREA2_ACTION.getAction),
]

A provided service will then dispatch the action that results from the rule. 然后,提供的服务将分派规则产生的操作。

My issue is that I need to integrate this library with the consumer's store. 我的问题是我需要将此库与消费者的商店集成在一起。 Is there a way to provide the ngrx store via some static module method or link it to my store behind the scenes in some way? 有没有办法通过某种静态模块方法提供ngrx商店,或者以某种方式将其链接到我的商店? DndModule.provideStore(???) I'm not sure what this would look like behind the scenes DndModule.provideStore(???)我不确定这在幕后会是什么样

You can look at how the router store is implemented, https://github.com/ngrx/router-store . 您可以通过以下网址查看如何实现路由器存储: https://github.com/ngrx/router-store The person trying to use your store will have to do some configuration and import the necessary actions, that they want to use. 尝试使用您的商店的人将必须进行一些配置并导入他们想使用的必要操作。 import { go, replace, search, show, back, forward } from '@ngrx/router-store';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM