fix(view-plugin): provide resolvers for memoized functions (#7801)

Before this change, memoization happened only on first
argument provided to the functions. Now the memoization
properly handle all arguments.

Refs #7800
This commit is contained in:
Vladimir Gorej
2022-01-27 08:46:03 +01:00
committed by GitHub
parent 87ccc247e0
commit d638e58527

View File

@@ -2,11 +2,22 @@ import { memoize } from "core/utils"
import { getComponent, render, withMappedContainer } from "./root-injects"
import { getDisplayName } from "./fn"
import memoizeN from "../../../helpers/memoizeN"
const memoizeForGetComponent = (fn) => {
const resolver = (...args) => JSON.stringify(args)
return memoize(fn, resolver)
}
const memoizeForWithMappedContainer = (fn) => {
const resolver = (...args) => args
return memoizeN(fn, resolver)
}
const viewPlugin = ({getComponents, getStore, getSystem}) => {
// getComponent should be passed into makeMappedContainer, _already_ memoized... otherwise we have a big performance hit ( think, really big )
const memGetComponent = memoize(getComponent(getSystem, getStore, getComponents))
const memMakeMappedContainer = memoize(withMappedContainer(getSystem, getStore, memGetComponent))
const memGetComponent = memoizeForGetComponent(getComponent(getSystem, getStore, getComponents))
const memMakeMappedContainer = memoizeForWithMappedContainer(withMappedContainer(getSystem, getStore, memGetComponent))
return {
rootInjects: {