Skip to content

Commit

Permalink
fix(view-plugin): provide resolvers for memoized functions (#7801)
Browse files Browse the repository at this point in the history
Before this change, memoization happened only on first
argument provided to the functions. Now the memoization
properly handle all arguments.

Refs #7800
  • Loading branch information
char0n committed Jan 27, 2022
1 parent 87ccc24 commit d638e58
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/core/plugins/view/index.js
Expand Up @@ -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: {
Expand Down

0 comments on commit d638e58

Please sign in to comment.