Skip to content

Commit

Permalink
Fix benchmarks that use value.change (#2569)
Browse files Browse the repository at this point in the history
* benchmark for large with selection

* inputer -> inputter

* value.change -> editor for slate benchmarks

* use editor in slate-react benchmarks

* prettier

* fix decorations benchmark
  • Loading branch information
jtadmor authored and ianstormtaylor committed Jan 30, 2019
1 parent f677f76 commit 8a0baac
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 64 deletions.
2 changes: 1 addition & 1 deletion benchmark/slate-react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports.run = function(include) {
const dir = resolve(benchmarkDir, benchmark)
const module = require(dir)
const fn = module.default
bench.input(() => module.input)
bench.input(module.input)

bench.run(input => {
fn(input)
Expand Down
13 changes: 9 additions & 4 deletions benchmark/slate-react/rendering/decoration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
const React = require('react')
const ReactDOM = require('react-dom/server')
const h = require('../../helpers/h')
const { Editor } = require('slate-react')
const { Editor } = require('slate')
const { Editor: EditorComponent } = require('slate-react')

module.exports.default = function(value) {
const el = React.createElement(Editor, { value })
const el = React.createElement(EditorComponent, { value })
ReactDOM.renderToStaticMarkup(el)
}

const value = (
let value = (
<value>
<document>
{Array.from(Array(10)).map(() => (
Expand Down Expand Up @@ -49,4 +50,8 @@ const decorations = texts.flatMap((t, index) => {
]
})

module.exports.input = value.change().setValue({ decorations }).value
value = value.setProperties({ decorations })

const editor = new Editor({ value })

module.exports.input = editor.value
66 changes: 66 additions & 0 deletions benchmark/slate-react/rendering/large-with-selection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/** @jsx h */
/* eslint-disable react/jsx-key */

const React = require('react')
const ReactDOM = require('react-dom/server')
const h = require('../../helpers/h')
const { Editor } = require('slate-react')

module.exports.default = function(value) {
const el = React.createElement(Editor, { value })
ReactDOM.renderToStaticMarkup(el)
}

module.exports.input = (
<value>
<document>
<paragraph>
Breve whipped ristretto ut as to go café au lait. Extra, skinny
trifecta, cup chicory medium cup dripper whipped coffee cultivar. Body
crema iced whipped, grounds turkish coffee steamed crema affogato.{' '}
<b>Skinny that wings aged cream,</b> grounds siphon coffee french press
mazagran irish roast.
</paragraph>
<block type="level-one">
<block type="level-two">
<block type="coffee-container">
<inline type="coffee">
Extra, brewed caffeine fair trade, whipped cup bar flavour grounds
organic. Café au lait blue mountain cortado saucer, macchiato ut
that caramelization flavour.
</inline>
<inline type="coffee">
Crema frappuccino so decaffeinated, sit café au lait irish
cultivar doppio café au lait. Dripper irish fair trade <anchor />kopi-luwak
ut beans skinny saucer.
</inline>
</block>
<block type="coffee-container">
<inline type="coffee">
Half and half, irish rich sugar medium frappuccino spoon. Whipped,
caramelization, caffeine french press cinnamon variety rich redeye
acerbic americano aftertaste. Shop crema filter seasonal, filter
aromatic, french press mazagran affogato cappuccino single origin.
</inline>
Plunger pot aromatic, crema, cultivar french press, skinny and
percolator so single origin. Id variety and cinnamon brewed flavour
cultivar acerbic half and half et<focus /> cappuccino.
<inline type="coffee">
Cup qui a barista crema white kopi-luwak chicory trifecta.
</inline>
</block>
</block>
</block>
{Array.from(Array(10)).map(() => (
<quote>
<paragraph>
<paragraph>
This is editable <b>rich</b> text, <i>much</i> better than a
textarea!
</paragraph>
</paragraph>
</quote>
))}
</document>
</value>
)
9 changes: 5 additions & 4 deletions benchmark/slate/changes/add-mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(change) {
change
module.exports.default = function(editor) {
editor
.addMark('bold')
.moveForward(5)
.addMark('bold')
Expand Down Expand Up @@ -37,6 +38,6 @@ const value = (
</value>
)

module.exports.input = function() {
return value.change()
module.exports.input = () => {
return new Editor({ value })
}
7 changes: 4 additions & 3 deletions benchmark/slate/changes/delete-backward.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(change) {
change
module.exports.default = function(editor) {
editor
.deleteBackward()
.deleteBackward()
.deleteBackward()
Expand All @@ -31,5 +32,5 @@ const value = (
)

module.exports.input = () => {
return value.change()
return new Editor({ value })
}
7 changes: 4 additions & 3 deletions benchmark/slate/changes/delete-forward.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(change) {
change
module.exports.default = function(editor) {
editor
.deleteForward()
.deleteForward()
.deleteForward()
Expand All @@ -31,5 +32,5 @@ const value = (
)

module.exports.input = () => {
return value.change()
return new Editor({ value })
}
7 changes: 4 additions & 3 deletions benchmark/slate/changes/insert-node-by-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(change) {
change
module.exports.default = function(editor) {
editor
.insertNodeByKey('a0', 0, <paragraph>Hello world</paragraph>)
.insertNodeByKey('a1', 1, <paragraph>Hello world</paragraph>)
.insertNodeByKey('a2', 2, <paragraph>Hello world</paragraph>)
Expand All @@ -29,5 +30,5 @@ const value = (
)

module.exports.input = function() {
return value.change()
return new Editor({ value })
}
12 changes: 6 additions & 6 deletions benchmark/slate/changes/insert-text-by-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function({ change, text }) {
change
module.exports.default = function(editor) {
editor
.insertTextByKey('T1', 0, 'one')
.insertTextByKey('T2', 5, 'two')
.insertTextByKey('T3', 10, 'three')
Expand All @@ -31,9 +32,8 @@ const value = (
</document>
</value>
)
const text = value.document.getLastText()
// const text = value.document.getLastText()

module.exports.input = function() {
const change = value.change()
return { change, text }
module.exports.input = () => {
return new Editor({ value })
}
9 changes: 5 additions & 4 deletions benchmark/slate/changes/insert-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(change) {
change
module.exports.default = function(editor) {
editor
.insertText('one')
.moveForward(5)
.insertText('two')
Expand Down Expand Up @@ -34,6 +35,6 @@ const value = (
</value>
)

module.exports.input = function() {
return value.change()
module.exports.input = () => {
return new Editor({ value })
}
3 changes: 2 additions & 1 deletion benchmark/slate/changes/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(change) {
change
Expand Down Expand Up @@ -35,5 +36,5 @@ const value = (
)

module.exports.input = function() {
return value.change()
return new Editor({ value }, { normalize: false })
}
8 changes: 4 additions & 4 deletions benchmark/slate/changes/remove-node-by-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function({ change, text }) {
change
module.exports.default = function(editor) {
editor
.removeNodeByKey('T1')
.removeNodeByKey('T2')
.removeNodeByKey('T3')
Expand Down Expand Up @@ -34,6 +35,5 @@ const value = (
const text = value.document.getLastText()

module.exports.input = function() {
const change = value.change()
return { change, text }
return new Editor({ value })
}
7 changes: 4 additions & 3 deletions benchmark/slate/changes/set-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(change) {
change
module.exports.default = function(editor) {
editor
.setBlocks('quote')
.setBlocks('paragraph')
.setBlocks('aside')
Expand All @@ -31,5 +32,5 @@ const value = (
)

module.exports.input = function() {
return value.change()
return new Editor({ value })
}
7 changes: 4 additions & 3 deletions benchmark/slate/changes/split-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(change) {
change
module.exports.default = function(editor) {
editor
.splitBlock()
.moveForward(5)
.splitBlock()
Expand Down Expand Up @@ -35,5 +36,5 @@ const value = (
)

module.exports.input = function() {
return value.change()
return new Editor({ value })
}
11 changes: 8 additions & 3 deletions benchmark/slate/models/get-active-marks-at-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(value) {
value.document.getActiveMarksAtRange(value.selection)
}

const value = (
let value = (
<value>
<document>
{Array.from(Array(10)).map(() => (
Expand All @@ -23,8 +24,12 @@ const value = (
</document>
</value>
)
.change()
.moveToRangeOfDocument().value

const editor = new Editor({ value })

editor.moveToRangeOfDocument()

value = editor.value

module.exports.input = function() {
return value
Expand Down
9 changes: 6 additions & 3 deletions benchmark/slate/models/get-leaf-blocks-at-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(value) {
value.document.getLeafBlocksAtRange(value.selection)
}

const value = (
let value = (
<value>
<document>
{Array.from(Array(10)).map(() => (
Expand All @@ -23,8 +24,10 @@ const value = (
</document>
</value>
)
.change()
.moveToRangeOfDocument().value

const editor = new Editor({ value })
editor.moveToRangeOfDocument()
value = editor.value

module.exports.input = () => {
return value
Expand Down
9 changes: 6 additions & 3 deletions benchmark/slate/models/get-leaf-inlines-at-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
/* eslint-disable react/jsx-key */

const h = require('../../helpers/h')
const { Editor } = require('slate')

module.exports.default = function(value) {
value.document.getLeafInlinesAtRange(value.selection)
}

const value = (
let value = (
<value>
<document>
{Array.from(Array(10)).map(() => (
Expand All @@ -23,8 +24,10 @@ const value = (
</document>
</value>
)
.change()
.moveToRangeOfDocument().value

const editor = new Editor({ value })
editor.moveToRangeOfDocument()
value = editor.value

module.exports.input = function() {
return value
Expand Down
Loading

0 comments on commit 8a0baac

Please sign in to comment.