I am learning ngrx Angular now. I have little confusion with ngrx syntax.
I know that the below Syntax of arrow function simply return "customer" object.
export const addCustomer = createAction(
'[Customer] Add Customer',
(customer: Customer) => {customer}
);
But what is this Syntax? What does this below round brackets "({customer})" mean? Am I missing something of ES6?
export const addCustomer = createAction(
'[Customer] Add Customer',
(customer: Customer) => ({customer})
);
(customer: Customer) => ({customer})
is a function which returns an object { customer: customer }
.
To understand it you need to be familiar with two concepts.
() => ({})
is the same as () => { return {}; }
.{ customer }
is the same as { customer: customer }
. Typescript allows such shortcuts in case property and variable names coincide (e.g. customer
key and customer
variable coincide in our case).