This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
/
metadata.ts
87 lines (77 loc) · 1.58 KB
/
metadata.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
'use strict';
/**
* A class used to interact with user level metadata.
*/
export
interface IMetadataCursor {
/**
* The metadata namespace.
*/
name: string;
/**
* Get the value of the metadata.
*/
getValue(): any;
/**
* Set the value of the metdata.
*/
setValue(value: any): void;
}
/**
* An implementation of a metadata cursor.
*/
export
class MetadataCursor implements IMetadataCursor {
/**
* Construct a new metadata cursor.
*
* @param name - The metadata namespace key.
*
* @param read - The read callback.
*
* @param write - The write callback.
*/
constructor(name: string, read: () => any, write: (value: any) => void) {
this._name = name;
this._read = read;
this._write = write;
}
/**
* Get the namespace key of the metadata.
*
* #### Notes
* This is a read-only property.
*/
get name(): string {
return this._name;
}
/**
* Dispose of the resources used by the cursor.
*
* #### Notes
* This is not meant to be called by user code.
*/
dispose(): void {
this._read = null;
this._write = null;
}
/**
* Get the value of the namespace data.
*/
getValue(): any {
let read = this._read;
return read();
}
/**
* Set the value of the namespace data.
*/
setValue(value: any): void {
let write = this._write;
write(value);
}
private _name = '';
private _read: () => string = null;
private _write: (value: string) => void = null;
}