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

[Feature] Object.assign helper #43

Open
sukima opened this issue Feb 17, 2025 · 1 comment
Open

[Feature] Object.assign helper #43

sukima opened this issue Feb 17, 2025 · 1 comment

Comments

@sukima
Copy link

sukima commented Feb 17, 2025

Current way to merge an object:

 {{#each-in (from-entries (append (entries foo) (entries bar))) as |key value|}}
    {{key}}:{{value}}
  {{/each}}

If this is also used with (hash) it will make for quite the complex setup:

 {{#each-in
    (from-entries
      (append
        (entries (hash foo="FOO"))
        (entries (hash bar="BAR"))
      )
    )
    as |key value|
  }}
    {{key}}:{{value}}
  {{/each}}

An alternative could use Object.assign instead:

 {{#each-in (assign (hash foo="FOO") (hash bar="BAR")) as |key value|}}
    {{key}}:{{value}}
  {{/each}}

Possible implementation:

import { helper } from '@ember/component/helper';

export function assign(objects: (Record<string, unknown> | null | undefined)[]) {
  return Object.assign({}, ...objects);
}

export default helper(assign);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants