Skip to content

Commit 02b68a9

Browse files
committed
[ change ] Simplify the Registry API
1 parent 20ba379 commit 02b68a9

File tree

4 files changed

+32
-41
lines changed

4 files changed

+32
-41
lines changed

lib/js/src/Main/Main.bs.js

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/js/src/Registry.bs.js

Lines changed: 7 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Main/Main.res

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ let activateWithoutContext = (
229229

230230
// filter out ".agda.git" files
231231
if isAgda(fileName) {
232-
Registry.getState(fileName)->Option.forEach(state => {
232+
Registry.get(fileName)
233+
->Option.flatMap(entry => entry.state)
234+
->Option.forEach(state => {
233235
// after switching tabs, the old editor would be "_disposed"
234236
// we need to replace it with this new one
235237
state.editor = editor
@@ -254,11 +256,9 @@ let activateWithoutContext = (
254256
if agdaModeFontSizeChanged || editorFontSizeChanged {
255257
let newFontSize = Config.Buffer.getFontSize()
256258
// find any existing State, so that we can update the font size in the view
257-
switch Registry.getAllStates()[0] {
259+
switch Registry.getAll()[0]->Option.flatMap(entry => entry.state) {
258260
| None => ()
259-
| Some(state) =>
260-
// panel->WebviewPanel.sendEvent(ConfigurationChange(fontSize))->ignore
261-
state->State__View.Panel.setFontSize(newFontSize)->Promise.done
261+
| Some(state) => state->State__View.Panel.setFontSize(newFontSize)->Promise.done
262262
}
263263
}
264264
})->subscribe
@@ -289,7 +289,7 @@ let activateWithoutContext = (
289289
| Load
290290
| Restart
291291
| InputMethod(Activate) =>
292-
switch Registry.getEntry(fileName) {
292+
switch Registry.get(fileName) {
293293
| None =>
294294
let state = initialize(
295295
platformDeps,
@@ -323,7 +323,8 @@ let activateWithoutContext = (
323323
| _ => ()
324324
}
325325
// dispatch
326-
switch Registry.getState(fileName) {
326+
327+
switch Registry.get(fileName)->Option.flatMap(entry => entry.state) {
327328
| None => None
328329
| Some(state) =>
329330
await State__Command.dispatchCommand(state, command)

src/Registry.res

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ module Module: {
66
}
77
}
88

9-
let getState: string => option<State.t>
10-
let getEntry: string => option<Entry.t>
11-
let getAllStates: unit => array<State.t>
9+
let get: string => option<Entry.t>
10+
let getAll: unit => array<Entry.t>
1211
let add: (string, State.t) => unit
1312
let remove: string => unit
1413
let removeAndDestroy: string => promise<unit>
@@ -41,15 +40,12 @@ module Module: {
4140
// FileName-Entry Registry
4241
let dict: Dict.t<Entry.t> = Dict.make()
4342

44-
let getEntry = fileName => dict->Dict.get(fileName)
45-
let getState = fileName => getEntry(fileName)->Option.flatMap(x => x.state)
46-
47-
// Get all existing States
48-
let getAllStates = () => dict->Dict.valuesToArray->Array.filterMap(getEntry => getEntry.state)
43+
let get = fileName => dict->Dict.get(fileName)
44+
let getAll = () => dict->Dict.valuesToArray
4945

5046
// Adds an instantiated State to the Registry
5147
let add = (fileName, state: State.t) => {
52-
switch getEntry(fileName) {
48+
switch get(fileName) {
5349
| None =>
5450
// entry not found, create a new one
5551
let entry = Entry.make(Some(state))
@@ -68,7 +64,7 @@ module Module: {
6864
let remove = fileName => Dict.delete(dict, fileName)
6965

7066
let removeAndDestroy = async fileName => {
71-
switch getEntry(fileName) {
67+
switch get(fileName) {
7268
| None => ()
7369
| Some(entry) =>
7470
remove(fileName)
@@ -92,7 +88,7 @@ module Module: {
9288

9389
// Requesting Semantic Tokens
9490
let requestSemanticTokens = async fileName => {
95-
switch getEntry(fileName) {
91+
switch get(fileName) {
9692
| Some(entry) =>
9793
let tokens = await entry.semanticTokens->Resource.get
9894
tokens

0 commit comments

Comments
 (0)