因此,我插入的内容越多(在大约 20 个装饰器替换之后),我的 Draft-js 编辑器就会变得非常慢(hacky)。我猜测这种行为是由于装饰器使用正则表达式检查整个编辑器内容,并在每次状态更改时用表情符号组件替换匹配项。我还为正则表达式找到的每个匹配创建实体,我通过使用编辑器状态作为道具来装饰组件来实现这一点。有没有办法让它更快?这是我的装饰器:
{
strategy: emojiStrategy,
component: decorateComponentWithProps(RenderEmoji, {
getEditorState: this.getEditorState,
setEditorState: this.onChange
})
}
Run Code Online (Sandbox Code Playgroud)
这是我的表情符号策略:
function emojiRegexF(regex, contentBlock, callback, contentState) {
const text = contentBlock.getText();
let matchArr, start;
while ((matchArr = regex.exec(text)) !== null) {
start = matchArr.index;
callback(start, start + matchArr[0].length);
}
}
function emojiStrategy(contentBlock, callback, contentState) {
emojiRegexF(EMOJI_REGEX, contentBlock, callback, contentState);
}
Run Code Online (Sandbox Code Playgroud)
这是我的 RenderEmoji 组件:
const RenderEmoji = props => {
const contentBlock = props.children[0].props.block;
const emojiKey = contentBlock.getEntityAt(props.children[0].props.start);
const emojiShortName = props.decoratedText;
if (!emojiKey) …Run Code Online (Sandbox Code Playgroud) 我找不到合适的正则表达式只从字符串中提取浮点数.请考虑以下字符串:
$string = "8x2.1 3x2";
Run Code Online (Sandbox Code Playgroud)
我想提取2.1,我尝试了以下但这给了我整数和浮点数:
preg_match_all('/[0-9,]+(?:\.[0-9]*)?/', $string, $matches);
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用 is_float检查浮点数但这也因某些原因返回整数.有任何想法吗?谢谢