Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Cache newSymbol created Symbols
Browse files Browse the repository at this point in the history
The observer decorator created 2 Symbols for each decorated component
instead of reusing the Symbols for props and state that was previously
created
  • Loading branch information
normano64 committed Dec 11, 2018
1 parent 73120d8 commit 98396f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function isStateless(component) {
}

let symbolId = 0
export function newSymbol(name) {
function createSymbol(name) {
if (typeof Symbol === "function") {
return Symbol(name)
}
Expand All @@ -14,6 +14,14 @@ export function newSymbol(name) {
return symbol
}

const createdSymbols = {}
export function newSymbol(name) {

This comment has been minimized.

Copy link
@theKashey

theKashey May 15, 2019

Contributor

I am not sure this change got published.
To be more concrete - https://unpkg.com/mobx-react@5.4.3/index.js - it wasn't

@mweststrate - could you please republish the package?

This comment has been minimized.

Copy link
@mweststrate

mweststrate via email May 16, 2019

Member
if (!createdSymbols[name]) {
createdSymbols[name] = createSymbol(name)
}
return createdSymbols[name]
}

const mobxMixins = newSymbol("patchMixins")
const mobxPatchedDefinition = newSymbol("patchedDefinition")

Expand Down
8 changes: 8 additions & 0 deletions test/no-symbol.test.js → test/symbol.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ delete global.Symbol
import React, { Component } from "react"
import { observer } from "../src"
import { asyncReactDOMRender, createTestRoot } from "./"
import { newSymbol } from "../src/utils/utils"

const testRoot = createTestRoot()

Expand All @@ -16,3 +17,10 @@ test("work without Symbol", async () => {
)
await asyncReactDOMRender(<Component1 />, testRoot)
})

test("cache newSymbol created Symbols", () => {
const symbol1 = newSymbol("name")
const symbol2 = newSymbol("name")

expect(symbol1).toEqual(symbol2)
})

0 comments on commit 98396f0

Please sign in to comment.