在aurelia中有没有用于状态管理的最佳实践或库?比如vue.js的集成状态管理?
我已经看到了一些建议,从一个简单的对象:
export default {
user: ...,
router: ...,
...,
}到一些aurelia redux集成:https://github.com/steelsojka/aurelia-redux-plugin
有没有人对复杂度较低的库有很好的体验?在我看来,Redux太过模式化了。我想要一些包装纸与较小的足迹类似于react的连身衣。
我使用了多次尝试:
store.js
存储为对象:
export default{
test: 'xxx'
};存储为类:
export default class Store{
constructor() {
this.test = 'xxx';
}
};在组件中,我像这样集成它:
import { inject } from 'aurelia-framework';
import store from './store';
@inject(store)
export class TestComp {
constructor(store){
this.store = store;
}
}或者甚至不注射:
import store from './store';
export class TestComp {
constructor(){
this.store = store;
}
}所有的组合似乎都工作得很好,并且存储在视图/组件之间保持同步。
其中一种比另一种有什么(缺点)?或者你会首先提出完全不同的方法吗?
发布于 2017-05-04 16:38:52
另一种方法是继续使用经典服务,但只通过操作更改存储中的单个状态。你可以在这里找到一篇关于它的文章http://pragmatic-coder.net/using-a-state-container-with-aurelia/。此方法在核心使用RxJS BehaviorSubject,订阅该a是为了使组件与状态同步。此外,与使用redux和重写应用程序相比,它为现有应用程序提供了一条更容易的升级路径。此外,还包括对Redux DevTools的支持;)
发布于 2018-07-26 17:32:35
与此同时,用于状态管理的官方Aurelia插件Aurelia-Store已经正式发布。看看the docs,看看它是如何工作的。
发布于 2017-01-11 21:00:09
我使用了类方法,然后在我需要的地方注入了类。
import {observable} from 'aurelia-framework';
import {Cookie} from 'aurelia-cookie';
export class AppConfig {
@observable companyCode;
@observable applCodeInUse;
@observable theme;
constructor() {
// Set up properties in here
}
// Some functions used for value conversion
}然后,因为注入的类被视为单例,所以只需注入AppConfig类并访问属性即可。
import {inject, NewInstance, ObserverLocator} from 'aurelia-framework';
import {AppConfig} from 'config/AppConfig';
@inject(AppConfig)
export class Form {
constructor(appConfig) {
this.appConfig = appConfig;
}
} 这显然与您的解决方案之一非常相似。我使用了一个类,因为有一些业务逻辑用于转换值等等。
你的疑虑似乎是关于这是否是糟糕的设计--但Aurelia的要点是只要你的代码遵循标准,你就可以自由地使用任何你喜欢的约定来实现你的结果。据我所知,这种方法并没有违反最新的JS标准。它也是轻量级和灵活的。我看不出有什么问题。
https://stackoverflow.com/questions/41553133
复制相似问题