Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement extend resource create a new object with added property #257

Closed
czerwinskilukasz1 opened this issue Jun 27, 2020 · 5 comments · Fixed by #492
Closed

Implement extend resource create a new object with added property #257

czerwinskilukasz1 opened this issue Jun 27, 2020 · 5 comments · Fixed by #492
Assignees
Labels
AskVM ./src/askvm/** enhancement New feature or request type:resources related to AskVM resources
Milestone

Comments

@czerwinskilukasz1
Copy link
Collaborator

While we have a resource for setting a value in an array (set resource), I think we don't have such for objects.

It is up to discussion whether a new resource should be created or rather set should be extended to work for objects.

@czerwinskilukasz1 czerwinskilukasz1 added enhancement New feature or request AskVM ./src/askvm/** labels Jun 27, 2020
@czerwinskilukasz1
Copy link
Collaborator Author

@mhagmajer , any thoughts?

@mhagmajer
Copy link
Contributor

Because of data mutability we need to support extend for objects.

let a = { firstName: 'John' }
let b = extend(a, { lastName: 'Smith' }

should return { firstName: 'John', lastName: 'Smith' }

@czerwinskilukasz1 czerwinskilukasz1 added the type:resources related to AskVM resources label Jul 8, 2020
@mhagmajer mhagmajer changed the title Implement a resource which adds a property to an object Implement extend resource create a new object with added property Jul 10, 2020
@czerwinskilukasz1
Copy link
Collaborator Author

@mhagmajer , would extend also change a value of an existing key?
E.g.:

let a = { firstName: 'John' }
a = extend(a, { firstName: 'Bill' }

@mhagmajer
Copy link
Contributor

@czerwinskilukasz1

let a = { firstName: 'John' } // object X
a = extend(a, { firstName: 'Bill' } // object Y

Object X is going to stay the same no matter what you do. Object Y will be creating by extending object X which will overwrite its only property. Variable a is like a pointer. It can change what it points to because it is declared with let. It initially points to object X and then it points to object Y. Object X and object Y are immutable.

@czerwinskilukasz1
Copy link
Collaborator Author

Yes, I know. That's why I wrote 'change' in italics. Anyways, you answered my question: yes, extend will also work on a key that is already defined. So using extend could be a workaround for updating a value in a map.
Anyway, don't we need a set resource for maps?

@YonatanKra YonatanKra self-assigned this Oct 7, 2020
@czerwinskilukasz1 czerwinskilukasz1 added this to the v1.3 milestone Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AskVM ./src/askvm/** enhancement New feature or request type:resources related to AskVM resources
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants