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

Commit

Permalink
Merge pull request #189 from accordproject/dl-debounce-parse
Browse files Browse the repository at this point in the history
feat(ClausePlugin): implement debounce for parsing clause on change
  • Loading branch information
DianaLease authored Oct 24, 2019
2 parents 95e5a97 + 60b3cf7 commit bd56118
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/plugins/ClausePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { getEventTransfer } from 'slate-react';
import { Template, Clause } from '@accordproject/cicero-core';
import { SlateTransformer } from '@accordproject/markdown-slate';
import _ from 'lodash';

import '../styles.css';
import ClauseComponent from '../components/ClauseComponent';
Expand Down Expand Up @@ -123,6 +124,11 @@ function ClausePlugin() {
});
}

/**
* Debounced parse to only be called after 1 second
*/
const debouncedParse = _.debounce(parse, 1000, { maxWait: 10000 });

/**
* Utility function to parse clauses within a paste value
*/
Expand Down Expand Up @@ -193,9 +199,8 @@ function ClausePlugin() {
if (!clauseNode) {
return next();
}
console.log('onChange - inside clause', clauseNode.toJSON());

parse(editor, clauseNode);
debouncedParse(editor, clauseNode);
return next();
}

Expand Down

0 comments on commit bd56118

Please sign in to comment.