Skip to content

Commit

Permalink
refactor: use object spread over Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 10, 2023
1 parent 2384d8e commit a793513
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/component/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ export class ComponentProps {
*/
defaults(values: Record<string, any>) {
if (values.class && this.#values['class']) {
const classes = Object.assign({}, values.class, this.#values.class)
return new ComponentProps(Object.assign({}, values, this.#values, { class: classes }))
const classes = { ...values.class, ...this.#values.class }
return new ComponentProps({ ...values, ...this.#values, class: classes })
}

return new ComponentProps(Object.assign({}, values, this.#values))
return new ComponentProps({ ...values, ...this.#values })
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/edge/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class Edge {
* Share locals with the current view context.
*
* ```js
* const view = edge.getRenderer()
* const view = edge.createRenderer()
*
* // local state for the current render
* view.share({ foo: 'bar' })
Expand Down
15 changes: 11 additions & 4 deletions src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ export class Template extends Macroable {
super()
this.#compiler = compiler
this.#processor = processor
this.#sharedState = lodash.merge({}, globals, locals)
this.#sharedState = compiler.compat
? lodash.merge({}, globals, locals)
: {
...globals,
...locals,
}
}

/**
Expand All @@ -74,7 +79,7 @@ export class Template extends Macroable {
* Render a compiled template with state
*/
#renderCompiled(compiledTemplate: CompiledTemplate, state: any) {
const templateState = Object.assign({}, this.#sharedState, state)
const templateState = { ...this.#sharedState, ...state }
const $context = {}

/**
Expand Down Expand Up @@ -127,11 +132,13 @@ export class Template extends Macroable {
slots: { [key: string]: any },
caller: { filename: string; line: number; col: number }
) {
return Object.assign({}, this.#sharedState, props, {
return {
...this.#sharedState,
...props,
$slots: slots,
$caller: caller,
$props: this.#compiler.compat ? new Props(props) : new ComponentProps(props),
})
}
}

/**
Expand Down

0 comments on commit a793513

Please sign in to comment.