Автор ngrx-форм здесь.
Следующее должно работать (с использованием ngrx v8 +). Я также рекомендую вам создавать свои действия в стиле ngrx v8 +, иначе вы не сможете должным образом использовать современный стиль редуктора.
const createTopicControl = createAction('[Entry Form] Add Topic Control', (name: string) => ({ name }));
const createLanguageControl = createAction('[Entry Form] Add Language Control', (name: string) => ({ name }));
const removeLanguageControl = createAction('[Entry Form] Remove Language Control', (name: string) => ({ name }));
const initialState: AddNewEntryFormState = {
newEntry: {
languages: {
formState: createFormGroupState<LanguageFormValue>('LANGUAGES_FORM', {
languages: {},
preferredLanguage: '',
}),
languageOptions: [],
},
topics: {
formState: createFormGroupState<TopicFormValue>('TOPICS_FORM', {
favoriteTopic: '',
otherTopics: {},
}),
topicsOptions: [],
},
}
}
export const addNewEntryFormStateReducer = createReducer(
initialState,
onNgrxForms(),
on(createTopicControl, (state, { name }) => {
// yes, nested reducers are ugly, look at options like immer.js
// to make this less messy
return {
...state,
newEntry: {
...state.newEntry,
topics: {
...state.newEntry.topics,
formState: updateGroup(state.newEntry.topics.formState, {
otherTopics: addGroupControl(name, {}),
}),
},
},
};
}),
on(createLanguageControl, (state, { name }) => {
return {
...state,
newEntry: {
...state.newEntry,
languages: {
...state.newEntry.languages,
formState: updateGroup(state.newEntry.languages.formState, {
languages: addGroupControl(name, {
language: '',
min: 0,
max: 0,
}),
}),
},
},
};
}),
on(removeLanguageControl, (state, { name }) => {
return {
...state,
newEntry: {
...state.newEntry,
languages: {
...state.newEntry.languages,
formState: updateGroup(state.newEntry.languages.formState, {
languages: removeGroupControl(name),
}),
},
},
};
}),
);
Надеюсь, это поможет.