Skip to content

Commit

Permalink
fix(tracker-context): remove unsupported for high order functions for…
Browse files Browse the repository at this point in the history
… setting props
  • Loading branch information
emkis committed Mar 19, 2023
1 parent fc57224 commit e2c98f6
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions src/tracker-context/tracker-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,23 @@ export function createTrackerContext(
return context.value
}

function setProps(
props:
| EventProperties
| ((previousProps: EventProperties) => EventProperties)
): void {
const updateContextValue = (newProps: EventProperties) => {
const updatedProps = { ...newProps }
context.value = updatedProps
}

if (typeof props === 'function') {
const previousProps = context.value
const newProps = props(previousProps)
return updateContextValue(newProps)
}

updateContextValue(props)
}

function handleSetProps(props: EventProperties) {
function setProps(props: EventProperties) {
const currentProps = getProps()
const newPropsCopy = { ...props }
const nextProps = { ...props }

logContextUpdated({
contextName: context.options.name,
currentProps,
newProps: newPropsCopy,
newProps: nextProps,
})
setProps(newPropsCopy)

context.value = nextProps
}

logContextCreated({
contextName: context.options.name,
properties: getProps(),
})

return {
context,
setProps: handleSetProps,
}
return { context, setProps }
}

0 comments on commit e2c98f6

Please sign in to comment.