Skip to content
campadrenalin edited this page Sep 14, 2011 · 1 revision

The JavaScript library is currently undergoing serious renovations to use Web Workers and less stuff. Here's the rough layout of how it will work for you when it's done.

Display

This is the type of object that a developer using the JSCT library will need to know and use most intimately. This is the piece that interacts with user I/O. It's designed to be as simple to use as possible, but there are still complications regarding its use.

Specifically, you cannot directly apply user actions when the user hits a key or pastes something or what have you. You have to call the appropriate methods, and let the display object apply them. This keeps the display in sync with the screen at all times, but can be hard to accomplish without writing event code to redirect user input from directly editing stuff. It would be nice if we could provide a user_update function corresponding to the onupdate property, but it would be surprisingly computationally expensive (a character-level diff in JavaScript on every user input event is murder).

methods:
    user_insert(pos, value)
    user_delete(start, end)
    user_cursor(pos)
    set_manager(bcp)

properties:
    function oninsert // called to insert text to screen, callback takes (pos, value)
    function ondelete // callback takes (start, end)
    function onmove // Moves the cursor, takes (pos)
    function onupdate // takes (value), which fully updates the text of the document

BCP

This is a type of manager, which simply means that you can set a display to use it to keep in touch with the outside world. The only manager in libctree1.0 is the BCP manager. It uses a Stream object given in its constructor to communicate with the BCP protocol, forwarding data between the outside link and the displays.

constructor(stream)
make_display(docname) // returns a Display

Stream

Currently the only supported type is "websocket", but that's fairly easy to expand. The "type" tells the Stream object which script to load as worker code, resolving type names to script addresses internally.

constructor(type, url)

Clone this wiki locally