xiaohongshu
xiaohongshu
Use this Skill when working in the Connect monorepo and needing to migrate legacy CustomStore or FeatureStore implementations to NgRx ComponentStore.
Full skill instructions
When to use this skill:
Connect/ng-app-monolith/)CustomStore or FeatureStore to modern NgRx ComponentStoreaddApiAction().withReducer() or addSocketAction().withReducer()Context: Connect's frontend is migrating from a custom store abstraction built on top of NgRx Store to standalone NgRx ComponentStore services. This provides better encapsulation, simpler testing, and eliminates the need for actions/reducers/selectors boilerplate.
Strictness hierarchy: ALWAYS/NEVER > PREFER > CAN > NOTE/EXAMPLE
ComponentStore<StateInterface>providedIn: 'root' for stores that need application-wide singleton behaviorreadonly propertiesinitialState to a constant; use eager initialization in the constructorStore suffix.store.tsEXAMPLE - Before (Legacy):
export const eventStore = new FeatureStore('event')
.addApiAction('loadEvents')
.withReducer((state, events) => ({ ...state, events }));
EXAMPLE - After (ComponentStore):
interface EventStoreState {
readonly events: Event[];
readonly isLoading: boolean;
}
const initialState: EventStoreState = {
events: [],
isLoading: false,
};
@Injectable({ providedIn: 'root' })
export class EventStore extends ComponentStore<EventStoreState> {
constructor() {
super(initialState);
}
}
addApiAction().withReducer() patterns with ComponentStore updaters and effectsaddSocketAction().withReducer() with updaters that accept observablestapResponse from @ngrx/operators (not @ngrx/component-store) for effect error handlingEXAMPLE - Replace API Actions with Effects:
// Legacy: addApiAction().withReducer()
// New: ComponentStore effect
readonly loadEvents = this.effect<void>(
pipe(
tap(() => this.setLoading(true)),
switchMap(() =>
this.#api.getEvents().pipe(
tapResponse({
next: (events) => this.setEvents(events),
error: (error) => this.#errorHandler.handle(error),
finalize: () => this.setLoading(false),
})
)
)
)
);
EXAMPLE - Replace Socket Actions with Updaters:
// Wire websocket observables directly to updaters in constructor
constructor() {
super(initialState);
// Subscribe to websocket actions and wire to updaters
this.addEvent(this.#wsService.action<Event>('AddEvent'));
this.updateEvent(this.#wsService.action<Event>('UpdateEvent'));
this.removeEvent(this.#wsService.action<{ id: string }>('RemoveEvent'));
// Trigger load on websocket connection
this.loadEvents(
this.#wsService.connectionState$.pipe(
filter((state) => state === 'Connected'),
map(() => undefined)
)
);
}
setState or patchState)set prefix for updaters that replace entire state slicesPayloadType | Observable<PayloadType> - wire observables directlyEXAMPLE:
// Updaters accept PayloadType | Observable<PayloadType>
readonly setEvents = this.updater<Event[]>((state, events) => ({
...state,
events,
}));
readonly addEvent = this.updater<Event>((state, event) => ({
...state,
events: [...state.events, event],
}));
readonly updateEvent = this.updater<Event>((state, updated) => ({
...state,
events: state.events.map((e) => (e.id === updated.id ? updated : e)),
}));
readonly removeEvent = this.updater<{ id: string }>((state, { id }) => ({
...state,
events: state.events.filter((e) => e.id !== id),
}));
readonly setLoading = this.updater<boolean>((state, isLoading) => ({
...state,
isLoading,
}));
$selectComponentStore.get() — always read via selectorswithLatestFrom(...)tap/tapResponse in selectorsEXAMPLE:
// Replace legacy selectors with ComponentStore selectors
readonly events$ = this.select((state) => state.events);
readonly isLoading$ = this.select((state) => state.isLoading);
// Computed/derived state
readonly activeEvents$ = this.select(
this.events$,
(events) => events.filter((e) => e.isActive)
);
tapResponse nested in inner pipes (after switchMap/mergeMap)pipe operator directly in effects: this.effect<Type>(pipe(...)) instead of this.effect<Type>((trigger$) => trigger$.pipe(...))switchMap for effects that should cancel previous requeststhis.effectName(of(undefined))) when calling effects without arguments
this.effectName() insteadtapResponse from @ngrx/operators, not @ngrx/component-storeEXAMPLE - Correct import:
import { tapResponse } from '@ngrx/operators';
EXAMPLE - Nested tapResponse pattern:
readonly saveEvent = this.effect<Event>(
pipe(
switchMap((event) =>
this.#api.saveEvent(event).pipe(
tapResponse({
next: (saved) => this.updateEvent(saved),
error: (error) => this.#errorHandler.handle(error),
})
)
)
)
);
ConnectSharedDataAccessWebsocketService in the store, not in a separate servicefilter and maptakeUntilDestroyed for root-provided stores
EXAMPLE:
readonly #wsService = inject(ConnectSharedDataAccessWebsocketService);
constructor() {
super(initialState);
// Wire websocket actions directly
this.addItem(this.#wsService.action<Item>('AddItem'));
this.updateItem(this.#wsService.action<Item>('UpdateItem'));
// Trigger load on connection
this.loadItems(
this.#wsService.connectionState$.pipe(
filter((state) => state === 'Connected'),
map(() => undefined)
)
);
}
inject() function instead of constructor injectioninject() calls first in the class as readonly fields#privateField syntax for private memberspublic or private keywords in TypeScriptEXAMPLE - Components Before:
readonly events$ = this.#store.select(eventSelectors.selectEvents);
ngOnInit() {
this.#store.dispatch(eventActions.loadEvents());
}
EXAMPLE - Components After:
readonly #eventStore = inject(EventStore);
readonly events$ = this.#eventStore.events$;
ngOnInit() {
this.#eventStore.loadEvents();
}
EXAMPLE - Services Before:
this.#store.dispatch(eventActions.updateEvent({ event }));
EXAMPLE - Services After:
this.#eventStore.saveEvent(event);
provide-event-store.ts)Store injection from components/services only using this storeOnStoreInit, OnStateInit)provideComponentStore; prefer standard providerstakeUntilDestroyed for root-provided stores
ComponentStore.get()
withLatestFrom() in effects for one-off readstapResponse from @ngrx/component-store
@ngrx/operators: import { tapResponse } from '@ngrx/operators';this.loadEvents() not this.loadEvents(of(undefined))libs/<product>/<application>/<domain>/<type>-<name>
academy, coaching, connect, sharedcms, shared, ufa (User-Facing Application)data-access, feature, ui, etc.EXAMPLE:
libs/connect/ufa/events/
├── data-access-event/
│ └── src/
│ ├── lib/
│ │ └── event.store.ts # New ComponentStore
│ └── index.ts # Export store
└── feature-events/
└── src/
└── lib/
└── event-list/
└── event-list.component.ts # Inject and use store
{ provide: Service, useValue: mockService } to mock dependenciesjest.spyOn() to verify side effectspatchState with // eslint-disable-next-line no-restricted-syntax for test setup onlydescribe() blocks: describe(MyStore.name, () => ...)it('should...')EXAMPLE:
describe(EventStore.name, () => {
let store: EventStore;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
EventStore,
{ provide: ApiService, useValue: mockApiService },
],
});
store = TestBed.inject(EventStore);
});
it('should load events', (done) => {
// Test selectors by subscribing
store.events$.pipe(skip(1)).subscribe((events) => {
expect(events).toEqual(mockEvents);
done();
});
// Trigger effect
store.loadEvents();
});
});
inject())readonly prop$ = this.select(...))readonly effectName = this.effect(...))readonly setX = this.updater(...))any type; use unknown when type is uncertain#privateField syntax for encapsulationpublic or private keywords in TypeScript class memberschangeDetection: ChangeDetectionStrategy.OnPush in @Component decoratorinject() calls first in the class as readonly fields@Input and @Output properties second in the class@if, @for, @switch) instead of *ngIf, *ngFor, *ngSwitch*ngrxLet directive or ngrxPush pipe to handle Observables
ngrxPush pipe over async for one-off async bindings in templates*ngrxLet or ngrxPush multiple times for the same Observable; instead assign it to a template variable using @letinject() function instead of constructor injectioninject() calls first as private readonly fieldsprovidedIn: 'root' option for singleton services@Component.providers for component-level storesyarn run format (from Connect/ng-app-monolith)yarn exec nx affected --targets=lint,test --skip-nx-cacheSee Instructions Section for code examples.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience