Skip to content

Instantly share code, notes, and snippets.

@hosseinzoda
Last active October 21, 2020 14:50
Show Gist options
  • Save hosseinzoda/2f9aa9b506f7c0421ca7ec118cd4b8cd to your computer and use it in GitHub Desktop.
Save hosseinzoda/2f9aa9b506f7c0421ca7ec118cd4b8cd to your computer and use it in GitHub Desktop.
How to change prediction of dynamic nodes.
/*
There are two functions in main.js for letter or word predition, You can modify it with _tree_dynamic_nodes_module_map variable
*/
// html/js/main.js L2063
var _tree_dynamic_nodes_module_map = {
'trees-switcher': {
render: _trees_switcher_dynamic_nodes,
},
'spell-word-prediction': {
render: _word_prediction_dynamic_nodes,
},
'spell-letter-prediction': {
render: _letter_prediction_dynamic_nodes,
},
};
/*
(_word_prediction_dynamic_nodes, _letter_prediction_dynamic_nodes)
These two functions are what renders the dynamic nodes of these predictions.
*/
/*
Both functions can are retreiving current context of pasco with the following snippet.
{
var txt = _get_current_spell_word(),
max_nodes = anode.meta['max-nodes'] || 3,
start_predicting_after_n_chars = parseInt(anode.meta['predict-after-n-chars']);
if (!isNaN(nchars) && txt.length < start_predicting_after_n_chars) {
return Promise.resolve({ nodes: [] });
}
}
*/
/*
The render function receive the dyn node as an input and should return a promise of replacements dynamic nodes.
Like this.
*/
async function _word_prediction_dynamic_nodes (anode) {
var txt = _get_current_spell_word(),
max_nodes = anode.meta['max-nodes'] || 3,
nchars = parseInt(anode.meta['predict-after-n-chars']);
if (!isNaN(nchars) && txt.length < nchars) {
return { nodes: [] }
}
return {
nodes: (await request_for_predictions(txt))
.map((item) => ({
text: item.value,
meta: {
'spell-word': item.value,
'spell-finish': anode.meta['spell-finish'],
}
}))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment