到目前为止,我找到的有关该主题的唯一信息是这篇文章。
我正在尝试用 2 个模块实现商店。
export interface RootState {
/** root state props **/
}
const store: StoreOptions<RootState> = {
modules: {
foo,
bar,
},
};
export default new Vuex.Store<RootState>(store);
Run Code Online (Sandbox Code Playgroud)
然后我有两个模块:
export interface FooState {
//(...)
}
export const foo: Module<FooState, RootState> = {
//(...)
};
export interface BarState {
//(...)
}
export const bar: Module<BarState, RootState> = {
//(...)
};
Run Code Online (Sandbox Code Playgroud)
一切正常,直到我遇到一种情况,我需要一个来自 foo 模块的 getter 来访问 bar 状态:
export const getters: GetterTree<FooState, RootState> = {
getInfo: (state, {}, rootState) …Run Code Online (Sandbox Code Playgroud) 我正在开发一个基于Lambda表达式的小型DI容器.我有代表lambda的接口:
@FunctionalInterface
public interface LambdaOp<T> {
T resolve();
}
Run Code Online (Sandbox Code Playgroud)
这是(非常简化的)容器:
public class Container {
private final Map<Class<?>, LambdaOp<?>> bindings;
public <T> void bind(Class<T> clazz, LambdaOp<? extends T> lambda) {
bindingd.put(clazz, lambda);
}
public <T> T resolve (Class<T> clazz) {
LambdaOp<?> lambda = bindings.get(clazz);
return (T) lambda.resolve();
}
}
Run Code Online (Sandbox Code Playgroud)
有了这个实现,我可以这样做:
container.bind(
FooInterface.class,
() -> {
FooImplementation foo = new FooImplementation();
foo.setParameterA(paramA);
//do whatever needed to configure it
return foo;
}
);
FooInterface foo2 = container.resolve(FooInterface.class);
Run Code Online (Sandbox Code Playgroud)
它工作正常,它很好,因为编译器不会让我做这样的事情:
container.bind(
FooInterface.class,
() -> …Run Code Online (Sandbox Code Playgroud) 我最近开始使用Java,但是在处理泛型类型时仍然感到困惑。以下是我遇到一些问题的简化方案。
我有一个类,其中保存一个使用Class类型作为Key的Map和该类对象的Collection:
public class GenericListInside {
private Map<Class<?>, List<?>> mapping = new HashMap<>();
public <T> void addListing(Class<T> clazz, List<T> object) {
mapping.put(clazz, object);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以毫无问题地调用addListing:
GenericListInside gli = new GenericListInside();
List<Foo> list = new ArrayList<>();
//add something to list
gli.addListing(Foo.class, list);
Run Code Online (Sandbox Code Playgroud)
现在,我决定创建一个Class以提供流畅的界面。就像是:
with(Foo.class).use(list);
Run Code Online (Sandbox Code Playgroud)
然后我来了:
public class FluidInserter<T> {
Class<T> clazz;
GenericListInside gli = new GenericListInside();
public FluidInserter with (Class<T> clazz) {
this.clazz = clazz;
return this;
}
public <T> void use(List<T> list) {
gli.addListing(clazz, list);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试编译时,我得到:
错误:(18,12)java:类util.GenericListInside中的方法addListing无法应用于给定类型; …
我最近迁移到 Intellij 2022.1.2,有时 IDE 会随机更改不同代码部分之间的行间距:注释/函数定义、导入/类定义等。
这种行为似乎非常不稳定,有时我只是重新启动 IDE,所有行都再次正常,有时更改是持久的。
这是一个例子:
这有点令人恼火。有什么办法可以禁用它吗?
我正在学习 Vue,刚刚进入路由章节。我可以使用 vue/cli 创建一个具有初始路由器配置的模板项目。这是路由器代码:
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home,
},
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ './views/About.vue'),
},
],
});
Run Code Online (Sandbox Code Playgroud)
根据代码和文档的注释,这应该足以延迟加载“关于”组件。
当我尝试加载应用程序页面时,会获取“about.js”脚本:
如果我导航到“关于”,浏览器将从磁盘缓存中获取脚本:
我很困惑。我期望只有在导航到“关于”页面后才能看到加载的脚本 about.js。我错过了什么吗?
java ×3
generics ×2
vue.js ×2
java-8 ×1
lambda ×1
lazy-loading ×1
router ×1
typescript ×1
vuex ×1