Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions packages/perspective/src/js/perspective.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,58 @@ class WebSocketServer extends Server {
}
}

_host(cache, name, input) {
if (cache[name] !== undefined) {
throw new Error(`"${name}" already exists`);
}
input.on_delete(() => {
delete cache[name];
});
cache[name] = input;
}

/**
* Expose a Perspective table through the WebSocket, allowing it to be
* accessed by a unique name.
* Expose a Perspective `table` through the WebSocket, allowing
* it to be accessed by a unique name from a client. Hosted objects
* are automatically `eject`ed when their `delete()` method is called.
*
* @param {String} name
* @param {Perspective.table} table
* @param {perspective.table} table `table` to host.
*/
host_table(name, table) {
this._tables[name] = table;
table.view({columns: []});
this._host(this._tables, name, table);
}

/**
* Expose a Perspective view through the WebSocket, allowing it to be
* accessed by a unique name.
* Expose a Perspective `view` through the WebSocket, allowing
* it to be accessed by a unique name from a client. Hosted objects
* are automatically `eject`ed when their `delete()` method is called.
*
* @param {String} name
* @param {Perspective.view} view
* @param {perspective.view} view `view` to host.
*/
host_view(name, view) {
this._views[name] = view;
this._host(this._views, name, view);
}

/**
* Cease hosting a `table` on this server. Hosted objects
* are automatically `eject`ed when their `delete()` method is called.
*
* @param {String} name
*/
eject_table(name) {
delete this._tables[name];
}

/**
* Cease hosting a `view` on this server. Hosted objects
* are automatically `eject`ed when their `delete()` method is called.
*
* @param {String} name
*/
eject_view(name) {
delete this._views[name];
}

close() {
Expand Down