Syntax sugar for (immutably) modifying js-objects
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 10.3k
- Forks
- 438
- PR merge metrics
- No merged PRs in 30d
Description
We have {"key": value} syntax sugar for creating JavaScript-objects. With records we have syntax to immutably update a record:
let meNextYear = {...me, age: me.age + 1};
For JavaScript interop it would be great to have similar syntax for objects, something like:
let meNextYear = {...me, "age": me##age + 1};
This because it's not possible to have a single function to update an object due to the typesystem. And Js.Obj.assign loses type information (see below).
Js.Obj.empty()->Js.Obj.assign(me)->Js.Obj.assign({"age": me##age + 1})
I am not sure if this is something very hard as it might need modification pretty deep inside of the (ocaml) compiler. But it would be great to have a good solution for this, JS-objects are still used in many libraries even if you don't interop with existing JavaScript code.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing record update syntax and the Js.Obj.assign examples described in the issue. The issue names no files or tests; done would require an agreed syntax for immutable JavaScript-object updates that preserves useful type information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, ocaml
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100