Replies: 3 comments 7 replies
-
I'm doing my own experiments regarding that at the moment and mostly orienting myself around https://www.angulararchitects.io/blog/ngrx-signal-store-deep-dive-flexible-and-type-safe-custom-extensions/ . For me that still isn't working properly when using it with generic fields, for your usecase it might though, depending on your needs. |
Beta Was this translation helpful? Give feedback.
-
@devkirr, I am not sure, if I understand you correctly, but the Feature needs to define the requirements for the store, not the other way around. For example, you could say that the store your feature is used in, needs to have a state property The way you do that would be: export function withValidateFeature() {
return signalStoreFeature(
{
state: type<{roleName: string}>(),
methods: type<{logout: () => void}>()
},
withMethods(store => ({
validate() {
if (store.roleName() !== 'admin') {
store.logout();
}
}
}))
)
} |
Beta Was this translation helpful? Give feedback.
-
@rainerhahnekamp some interesting things here. But my exact need is this: type AuthFeature = {
roleName: Signal<string>;
logout(): void;
};
const withAuthFeature = (() => {
return signalStoreFeature(
{
state: {}
methods: {},
},
withState({ roleName: 'admin' }),
withMethods((store) => ({
logout() {},
})),
);
}) satisfies () => SignalStoreFeature<
EmptyFeatureResult,
EmptyFeatureResult & {
state: { roleName: string };
methods: { logout: () => void };
}
>;
export const Store = signalStore(
withAuthFeature()
);
function validate(store: AuthFeature) {
if (store.roleName() !== 'admin') {
store.logout();
}
}
validate(store); // => would it work? |
Beta Was this translation helpful? Give feedback.
-
I would like to know if it’s possible to refer to the type of a particular store custom feature?
With Type? referring the custom feature's state, method, computed, etc. and not the AuthStore.
The use case: I want to provide through an Input of a Directive the CustomFeatureStore for this directive to interact with the provided Store of the component that use this directive in his template.
Beta Was this translation helpful? Give feedback.
All reactions