Component state #17
Answered
by
NetanelBasal
strigefleur
asked this question in
Q&A
-
Back in Akita I used recipe for local component state to get multiple instances of same state. What would be the correct implementation in Elf? |
Beta Was this translation helpful? Give feedback.
Answered by
NetanelBasal
Oct 11, 2021
Replies: 1 comment 11 replies
-
There are many ways to do it. Here is one of them: const { state, config } = createState(
withProps<{ counter: number }>({ counter: 0 })
);
@Injectable()
export class CounterRepository {
counter$ = this.store.pipe(select(({ counter }) => counter));
constructor(private store: Store<StoreDef<typeof state>>) { }
}
export const counterProvider = {
provide: CounterRepository,
useFactory() {
return new CounterRepository(new Store({
name: `counter-${Math.random().toFixed(3)}`,
state,
config,
}))
}
} |
Beta Was this translation helpful? Give feedback.
11 replies
Answer selected by
strigefleur
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are many ways to do it. Here is one of them: