/lacona-addon-stateful

Add statefulness the Lacona parser

Primary LanguageJavaScriptMIT LicenseMIT

lacona-addon-stateful

Build Status Coverage Status npm

This library works with the lacona parser.

Typically, the lacona parser simply emits data for each parse as quickly as possible. Each parse is completely independent of all other parses.

However, for GUIs, it may be useful to keep track of state between parses, to correctly interpret keystrokes, handle animations, and more.

This module implements this stateful behavior, by means of a Transform stream.

Parse results are considered to be "the same" if the output of serializer is the same. lacona-util-fulltext is a simple function that serializes an OutputOption by concatenating its Match, Suggestion, and Completion.

##Example

var lacona = require('lacona');
var Stateful = require('lacona-addon-stateful');
var fulltext = require('lacona-util-fulltext');

var parser = new lacona.Parser();
//configure the parser if need be

var stateful = new Stateful({serializer: fulltext});

src
	.pipe(parser)
	.pipe(stateful)
	.pipe(process.stdout);

##Docs

StatefulParser is an Transform stream that should be piped the output of lacona.Parser. It emits objects in the form

{
	id: id,
	event: eventName,
	data: data
}

Where event will be either 'insert', 'update', or 'delete'. For 'insert' and 'update', an OutputOption will be provided as the data property.

StatefulParser is useful for interactive parsing sessions. Because inserts, updates, and deletes are provided independently, order can be maintained between requests and interfaces can be managed properly.