File tree Expand file tree Collapse file tree 3 files changed +19
-8
lines changed
Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -167,17 +167,15 @@ describe('devToolsDockHost', () => {
167167 it ( 'should preserve dock in values() after update' , ( ) => {
168168 const host = new DevToolsDockHost ( mockContext )
169169
170- host . register ( {
170+ const { update } = host . register ( {
171171 type : 'iframe' ,
172172 id : 'test' ,
173173 title : 'Original' ,
174174 icon : 'icon' ,
175175 url : 'http://localhost:3000' ,
176176 } )
177177
178- host . update ( {
179- type : 'iframe' ,
180- id : 'test' ,
178+ update ( {
181179 title : 'Updated' ,
182180 icon : 'newicon' ,
183181 url : 'http://localhost:3001' ,
Original file line number Diff line number Diff line change @@ -14,12 +14,23 @@ export class DevToolsDockHost implements DevToolsDockHostType {
1414 return Array . from ( this . views . values ( ) )
1515 }
1616
17- register ( view : DevToolsDockUserEntry , force ?: boolean ) : void {
17+ register < T extends DevToolsDockUserEntry > ( view : T , force ?: boolean ) : {
18+ update : ( patch : Partial < T > ) => void
19+ } {
1820 if ( this . views . has ( view . id ) && ! force ) {
1921 throw new Error ( `Dock with id "${ view . id } " is already registered` )
2022 }
2123 this . views . set ( view . id , view )
2224 this . events . emit ( 'dock:entry:updated' , view )
25+
26+ return {
27+ update : ( patch ) => {
28+ if ( patch . id && patch . id !== view . id ) {
29+ throw new Error ( `Cannot change the id of a dock. Use register() to add new docks.` )
30+ }
31+ this . update ( Object . assign ( this . views . get ( view . id ) ! , patch ) )
32+ } ,
33+ }
2334 }
2435
2536 update ( view : DevToolsDockUserEntry ) : void {
Original file line number Diff line number Diff line change 11import type { EventEmitter } from './events'
22
33export interface DevToolsDockHost {
4- views : Map < string , DevToolsDockUserEntry >
5- events : EventEmitter < {
4+ readonly views : Map < string , DevToolsDockUserEntry >
5+ readonly events : EventEmitter < {
66 'dock:entry:updated' : ( entry : DevToolsDockUserEntry ) => void
77 } >
88
9- register : ( entry : DevToolsDockUserEntry ) => void
9+ register : < T extends DevToolsDockUserEntry > ( entry : T , force ?: boolean ) => {
10+ update : ( patch : Partial < T > ) => void
11+ }
1012 update : ( entry : DevToolsDockUserEntry ) => void
1113 values : ( ) => DevToolsDockUserEntry [ ]
1214}
You can’t perform that action at this time.
0 commit comments