mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-27 00:54:22 +02:00
fix benchmarks by exposing memoization utils
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { basename, extname, resolve } from 'path'
|
import { basename, extname, resolve } from 'path'
|
||||||
import { __clear } from '../../slate/lib/utils/memoize'
|
import { resetMemoization } from 'slate'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Benchmarks.
|
* Benchmarks.
|
||||||
@@ -20,7 +20,7 @@ categories.forEach(category => {
|
|||||||
|
|
||||||
if (category == 'models') {
|
if (category == 'models') {
|
||||||
after(() => {
|
after(() => {
|
||||||
__clear()
|
resetMemoization()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { basename, extname, resolve } from 'path'
|
import { basename, extname, resolve } from 'path'
|
||||||
import { __clear } from '../../slate/lib/utils/memoize'
|
import { resetMemoization } from 'slate'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Benchmarks.
|
* Benchmarks.
|
||||||
@@ -20,7 +20,7 @@ categories.forEach(category => {
|
|||||||
|
|
||||||
if (category == 'models') {
|
if (category == 'models') {
|
||||||
after(() => {
|
after(() => {
|
||||||
__clear()
|
resetMemoization()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable react/jsx-key */
|
/* eslint-disable react/jsx-key */
|
||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
import { __clear } from '../../lib/utils/memoize'
|
import { resetMemoization } from '../..'
|
||||||
|
|
||||||
export default function({ change, keys }) {
|
export default function({ change, keys }) {
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
@@ -16,7 +16,7 @@ export function before(value) {
|
|||||||
.getTexts()
|
.getTexts()
|
||||||
.toArray()
|
.toArray()
|
||||||
.map(t => t.key)
|
.map(t => t.key)
|
||||||
__clear()
|
resetMemoization()
|
||||||
return { change, keys }
|
return { change, keys }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable react/jsx-key */
|
/* eslint-disable react/jsx-key */
|
||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
import { __clear } from '../../lib/utils/memoize'
|
import { resetMemoization } from '../..'
|
||||||
|
|
||||||
export default function({ change, text }) {
|
export default function({ change, text }) {
|
||||||
change.insertTextByKey(text.key, 0, 'a')
|
change.insertTextByKey(text.key, 0, 'a')
|
||||||
@@ -11,7 +11,7 @@ export default function({ change, text }) {
|
|||||||
export function before(value) {
|
export function before(value) {
|
||||||
const change = value.change()
|
const change = value.change()
|
||||||
const text = value.document.getLastText()
|
const text = value.document.getLastText()
|
||||||
__clear()
|
resetMemoization()
|
||||||
return { change, text }
|
return { change, text }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { basename, extname, resolve } from 'path'
|
import { basename, extname, resolve } from 'path'
|
||||||
import { __clear } from '../lib/utils/memoize'
|
import { resetMemoization } from '..'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Benchmarks.
|
* Benchmarks.
|
||||||
@@ -20,7 +20,7 @@ categories.forEach(category => {
|
|||||||
|
|
||||||
if (category == 'models') {
|
if (category == 'models') {
|
||||||
after(() => {
|
after(() => {
|
||||||
__clear()
|
resetMemoization()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable react/jsx-key */
|
/* eslint-disable react/jsx-key */
|
||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
import { __clear } from '../../lib/utils/memoize'
|
import { resetMemoization } from '../..'
|
||||||
|
|
||||||
export default function(text) {
|
export default function(text) {
|
||||||
text.getLeaves()
|
text.getLeaves()
|
||||||
@@ -10,7 +10,7 @@ export default function(text) {
|
|||||||
|
|
||||||
export function before(value) {
|
export function before(value) {
|
||||||
const text = value.document.getFirstText()
|
const text = value.document.getFirstText()
|
||||||
__clear()
|
resetMemoization()
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable react/jsx-key */
|
/* eslint-disable react/jsx-key */
|
||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
import { __clear } from '../../lib/utils/memoize'
|
import { resetMemoization } from '../..'
|
||||||
|
|
||||||
export default function({ value, text }) {
|
export default function({ value, text }) {
|
||||||
value.document.getPath(text.key)
|
value.document.getPath(text.key)
|
||||||
@@ -10,7 +10,7 @@ export default function({ value, text }) {
|
|||||||
|
|
||||||
export function before(value) {
|
export function before(value) {
|
||||||
const text = value.document.getLastText()
|
const text = value.document.getLastText()
|
||||||
__clear()
|
resetMemoization()
|
||||||
return { value, text }
|
return { value, text }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable react/jsx-key */
|
/* eslint-disable react/jsx-key */
|
||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
import { __clear } from '../../lib/utils/memoize'
|
import { resetMemoization } from '../..'
|
||||||
|
|
||||||
export default function({ value, keys }) {
|
export default function({ value, keys }) {
|
||||||
keys.forEach(key => {
|
keys.forEach(key => {
|
||||||
@@ -15,7 +15,7 @@ export function before(value) {
|
|||||||
.getTexts()
|
.getTexts()
|
||||||
.toArray()
|
.toArray()
|
||||||
.map(t => t.key)
|
.map(t => t.key)
|
||||||
__clear()
|
resetMemoization()
|
||||||
return { value, keys }
|
return { value, keys }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable react/jsx-key */
|
/* eslint-disable react/jsx-key */
|
||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
import { __clear } from '../../lib/utils/memoize'
|
import { resetMemoization } from '../..'
|
||||||
|
|
||||||
export default function({ value, text }) {
|
export default function({ value, text }) {
|
||||||
value.document.hasNode(text.key)
|
value.document.hasNode(text.key)
|
||||||
@@ -10,7 +10,7 @@ export default function({ value, text }) {
|
|||||||
|
|
||||||
export function before(value) {
|
export function before(value) {
|
||||||
const text = value.document.getLastText()
|
const text = value.document.getLastText()
|
||||||
__clear()
|
resetMemoization()
|
||||||
return { value, text }
|
return { value, text }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable react/jsx-key */
|
/* eslint-disable react/jsx-key */
|
||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
import { __clear } from '../../lib/utils/memoize'
|
import { resetMemoization } from '../..'
|
||||||
|
|
||||||
export default function({ value, next }) {
|
export default function({ value, next }) {
|
||||||
value.document.updateNode(next)
|
value.document.updateNode(next)
|
||||||
@@ -13,7 +13,7 @@ export function before(value) {
|
|||||||
const { size } = texts
|
const { size } = texts
|
||||||
const text = texts.get(Math.round(size / 2))
|
const text = texts.get(Math.round(size / 2))
|
||||||
const next = text.insertText(0, 'some text')
|
const next = text.insertText(0, 'some text')
|
||||||
__clear()
|
resetMemoization()
|
||||||
return { value, next }
|
return { value, next }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@ import Stack from './models/stack'
|
|||||||
import Text from './models/text'
|
import Text from './models/text'
|
||||||
import Value from './models/value'
|
import Value from './models/value'
|
||||||
import { resetKeyGenerator, setKeyGenerator } from './utils/generate-key'
|
import { resetKeyGenerator, setKeyGenerator } from './utils/generate-key'
|
||||||
|
import { resetMemoization, useMemoization } from './utils/memoize'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export.
|
* Export.
|
||||||
@@ -45,6 +46,8 @@ export {
|
|||||||
Value,
|
Value,
|
||||||
resetKeyGenerator,
|
resetKeyGenerator,
|
||||||
setKeyGenerator,
|
setKeyGenerator,
|
||||||
|
resetMemoization,
|
||||||
|
useMemoization,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -67,4 +70,6 @@ export default {
|
|||||||
Value,
|
Value,
|
||||||
resetKeyGenerator,
|
resetKeyGenerator,
|
||||||
setKeyGenerator,
|
setKeyGenerator,
|
||||||
|
resetMemoization,
|
||||||
|
useMemoization,
|
||||||
}
|
}
|
||||||
|
@@ -55,4 +55,5 @@ resetKeyGenerator()
|
|||||||
* @type {Object}
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { generateKey as default, setKeyGenerator, resetKeyGenerator }
|
export default generateKey
|
||||||
|
export { setKeyGenerator, resetKeyGenerator }
|
||||||
|
@@ -172,7 +172,7 @@ function setIn(map, keys, value) {
|
|||||||
* @return {Void}
|
* @return {Void}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function __clear() {
|
function resetMemoization() {
|
||||||
CACHE_KEY++
|
CACHE_KEY++
|
||||||
|
|
||||||
if (CACHE_KEY >= Number.MAX_SAFE_INTEGER) {
|
if (CACHE_KEY >= Number.MAX_SAFE_INTEGER) {
|
||||||
@@ -187,7 +187,7 @@ function __clear() {
|
|||||||
* @return {Void}
|
* @return {Void}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function __enable(enabled) {
|
function useMemoization(enabled) {
|
||||||
ENABLED = enabled
|
ENABLED = enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,4 +197,5 @@ function __enable(enabled) {
|
|||||||
* @type {Object}
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { memoize as default, __clear, __enable }
|
export default memoize
|
||||||
|
export { resetMemoization, useMemoization }
|
||||||
|
Reference in New Issue
Block a user