can we partially update the state of a component in angular 6/ngrx












1















I have a component named FormComponent and i have setup a reducer to managed the state of this component named formReducer.



On Initial load i get the data in following format



formInfo: {
form1Data: {form1properties},
form2Data: {form2Properties},
form3Data: {form3Properties}
}


If i want to perform partial save on form1, How can i update my state.info.form1Data without affecting (resetting) form2Data & form3Data.



I want to perform a partial state update



my component HTML is in following format:



<div>
<form> form1Data </form> /*api 1*/
<form nestedForm> /*api 2*
<form> form2Data </form>
<form> form3Data </form>
</form>
</div>


my Component Code inside ngOnInit:



this.actions.pipe(
ofType(GET_FORM_INFO_SUCCESS),
mergeMap(v => this.state)
).subscribe((data: any) => {
if(data && data.formInfo) {
//inits basic (form1Data) & nested form (form2Data & form3Data)
this.initForm(data.formInfo);
}
})


my reducer is in following format:



defaultState = {
formInfo: {
form1Data: {
somePropertiesCollection: defaultValues
},
form2Data: {
somePropertiesCollection: defaultValues
},
form3Data: {
somePropertiesCollection: defaultValues
}
}
}

function formreducer(state: defaultState, action: ALL) {
case GET_FORM_INFO_SUCCESS:
return {state, ...action.payload}
case FORM_SECTION_1_SAVE_SUCCESS:
const form1Data = action.payload;
const formInfo = {...state.formInfo, form1Data}
return {...state, formInfo}
case FORM_SECTION_2_SAVE_SUCCESS:
const {form2Data, form3Data} = action.payload;
const formInfo = {...state.formInfo, form2Data, form3Data}
return {...state, formInfo}
}


I just started working on ngrx store and angular 6. I was able to do small stuff but facing problem in complex structure.










share|improve this question

























  • show us your formreducer defination and update action

    – Just code
    Nov 15 '18 at 13:06
















1















I have a component named FormComponent and i have setup a reducer to managed the state of this component named formReducer.



On Initial load i get the data in following format



formInfo: {
form1Data: {form1properties},
form2Data: {form2Properties},
form3Data: {form3Properties}
}


If i want to perform partial save on form1, How can i update my state.info.form1Data without affecting (resetting) form2Data & form3Data.



I want to perform a partial state update



my component HTML is in following format:



<div>
<form> form1Data </form> /*api 1*/
<form nestedForm> /*api 2*
<form> form2Data </form>
<form> form3Data </form>
</form>
</div>


my Component Code inside ngOnInit:



this.actions.pipe(
ofType(GET_FORM_INFO_SUCCESS),
mergeMap(v => this.state)
).subscribe((data: any) => {
if(data && data.formInfo) {
//inits basic (form1Data) & nested form (form2Data & form3Data)
this.initForm(data.formInfo);
}
})


my reducer is in following format:



defaultState = {
formInfo: {
form1Data: {
somePropertiesCollection: defaultValues
},
form2Data: {
somePropertiesCollection: defaultValues
},
form3Data: {
somePropertiesCollection: defaultValues
}
}
}

function formreducer(state: defaultState, action: ALL) {
case GET_FORM_INFO_SUCCESS:
return {state, ...action.payload}
case FORM_SECTION_1_SAVE_SUCCESS:
const form1Data = action.payload;
const formInfo = {...state.formInfo, form1Data}
return {...state, formInfo}
case FORM_SECTION_2_SAVE_SUCCESS:
const {form2Data, form3Data} = action.payload;
const formInfo = {...state.formInfo, form2Data, form3Data}
return {...state, formInfo}
}


I just started working on ngrx store and angular 6. I was able to do small stuff but facing problem in complex structure.










share|improve this question

























  • show us your formreducer defination and update action

    – Just code
    Nov 15 '18 at 13:06














1












1








1








I have a component named FormComponent and i have setup a reducer to managed the state of this component named formReducer.



On Initial load i get the data in following format



formInfo: {
form1Data: {form1properties},
form2Data: {form2Properties},
form3Data: {form3Properties}
}


If i want to perform partial save on form1, How can i update my state.info.form1Data without affecting (resetting) form2Data & form3Data.



I want to perform a partial state update



my component HTML is in following format:



<div>
<form> form1Data </form> /*api 1*/
<form nestedForm> /*api 2*
<form> form2Data </form>
<form> form3Data </form>
</form>
</div>


my Component Code inside ngOnInit:



this.actions.pipe(
ofType(GET_FORM_INFO_SUCCESS),
mergeMap(v => this.state)
).subscribe((data: any) => {
if(data && data.formInfo) {
//inits basic (form1Data) & nested form (form2Data & form3Data)
this.initForm(data.formInfo);
}
})


my reducer is in following format:



defaultState = {
formInfo: {
form1Data: {
somePropertiesCollection: defaultValues
},
form2Data: {
somePropertiesCollection: defaultValues
},
form3Data: {
somePropertiesCollection: defaultValues
}
}
}

function formreducer(state: defaultState, action: ALL) {
case GET_FORM_INFO_SUCCESS:
return {state, ...action.payload}
case FORM_SECTION_1_SAVE_SUCCESS:
const form1Data = action.payload;
const formInfo = {...state.formInfo, form1Data}
return {...state, formInfo}
case FORM_SECTION_2_SAVE_SUCCESS:
const {form2Data, form3Data} = action.payload;
const formInfo = {...state.formInfo, form2Data, form3Data}
return {...state, formInfo}
}


I just started working on ngrx store and angular 6. I was able to do small stuff but facing problem in complex structure.










share|improve this question
















I have a component named FormComponent and i have setup a reducer to managed the state of this component named formReducer.



On Initial load i get the data in following format



formInfo: {
form1Data: {form1properties},
form2Data: {form2Properties},
form3Data: {form3Properties}
}


If i want to perform partial save on form1, How can i update my state.info.form1Data without affecting (resetting) form2Data & form3Data.



I want to perform a partial state update



my component HTML is in following format:



<div>
<form> form1Data </form> /*api 1*/
<form nestedForm> /*api 2*
<form> form2Data </form>
<form> form3Data </form>
</form>
</div>


my Component Code inside ngOnInit:



this.actions.pipe(
ofType(GET_FORM_INFO_SUCCESS),
mergeMap(v => this.state)
).subscribe((data: any) => {
if(data && data.formInfo) {
//inits basic (form1Data) & nested form (form2Data & form3Data)
this.initForm(data.formInfo);
}
})


my reducer is in following format:



defaultState = {
formInfo: {
form1Data: {
somePropertiesCollection: defaultValues
},
form2Data: {
somePropertiesCollection: defaultValues
},
form3Data: {
somePropertiesCollection: defaultValues
}
}
}

function formreducer(state: defaultState, action: ALL) {
case GET_FORM_INFO_SUCCESS:
return {state, ...action.payload}
case FORM_SECTION_1_SAVE_SUCCESS:
const form1Data = action.payload;
const formInfo = {...state.formInfo, form1Data}
return {...state, formInfo}
case FORM_SECTION_2_SAVE_SUCCESS:
const {form2Data, form3Data} = action.payload;
const formInfo = {...state.formInfo, form2Data, form3Data}
return {...state, formInfo}
}


I just started working on ngrx store and angular 6. I was able to do small stuff but facing problem in complex structure.







angular redux ngrx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 8:57







Mayur Patil

















asked Nov 15 '18 at 13:04









Mayur PatilMayur Patil

1048




1048













  • show us your formreducer defination and update action

    – Just code
    Nov 15 '18 at 13:06



















  • show us your formreducer defination and update action

    – Just code
    Nov 15 '18 at 13:06

















show us your formreducer defination and update action

– Just code
Nov 15 '18 at 13:06





show us your formreducer defination and update action

– Just code
Nov 15 '18 at 13:06












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320120%2fcan-we-partially-update-the-state-of-a-component-in-angular-6-ngrx%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320120%2fcan-we-partially-update-the-state-of-a-component-in-angular-6-ngrx%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."