Sreehari
Sreehari

Reputation: 1370

ngrx 8 createAction syntax

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})
);

Upvotes: 0

Views: 97

Answers (1)

Aram Khachatrian
Aram Khachatrian

Reputation: 399

(customer: Customer) => ({customer}) is a function which returns an object { customer: customer }.

To understand it you need to be familiar with two concepts.

  1. () => ({}) is the same as () => { return {}; }.
  2. { 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).

Upvotes: 1

Related Questions