mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) move client code to core
Summary: This moves all client code to core, and makes minimal fix-ups to get grist and grist-core to compile correctly. The client works in core, but I'm leaving clean-up around the build and bundles to follow-up. Test Plan: existing tests pass; server-dev bundle looks sane Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2627
This commit is contained in:
55
app/client/components/ClientScope.ts
Normal file
55
app/client/components/ClientScope.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import * as dispose from 'app/client/lib/dispose';
|
||||
import {Storage} from 'app/plugin/StorageAPI';
|
||||
import {checkers} from 'app/plugin/TypeCheckers';
|
||||
import {Rpc} from 'grain-rpc';
|
||||
|
||||
/**
|
||||
* Implementation of interfaces whose lifetime is that of the client.
|
||||
*/
|
||||
export class ClientScope extends dispose.Disposable {
|
||||
private _pluginStorage = new Map<string, Storage>();
|
||||
|
||||
public create() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Make interfaces available for a plugin with a given name. Implementations
|
||||
* are attached directly to the supplied rpc object.
|
||||
*/
|
||||
public servePlugin(pluginId: string, rpc: Rpc) {
|
||||
// We have just one interface right now, storage. We want to keep ownership
|
||||
// of storage, so it doesn't go away when the plugin is closed. So we cache
|
||||
// it.
|
||||
let storage = this._pluginStorage.get(pluginId);
|
||||
if (!storage) {
|
||||
storage = this._implementStorage();
|
||||
this._pluginStorage.set(pluginId, storage);
|
||||
}
|
||||
rpc.registerImpl<Storage>("storage", storage, checkers.Storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an implementation of the Storage interface.
|
||||
*/
|
||||
private _implementStorage(): Storage {
|
||||
const data = new Map<string, any>();
|
||||
return {
|
||||
getItem(key: string): any {
|
||||
return data.get(key);
|
||||
},
|
||||
hasItem(key: string): boolean {
|
||||
return data.has(key);
|
||||
},
|
||||
setItem(key: string, value: any) {
|
||||
data.set(key, value);
|
||||
},
|
||||
removeItem(key: string) {
|
||||
data.delete(key);
|
||||
},
|
||||
clear() {
|
||||
data.clear();
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user