File tree Expand file tree Collapse file tree 3 files changed +51
-3
lines changed
Expand file tree Collapse file tree 3 files changed +51
-3
lines changed Original file line number Diff line number Diff line change 1818 "prepare" : " is-ci || husky install"
1919 },
2020 "files" : [
21- " src" ,
22- " dist" ,
21+ " src/ " ,
22+ " dist/ " ,
2323 " logo.png"
2424 ],
2525 "devDependencies" : {
Original file line number Diff line number Diff line change @@ -114,4 +114,25 @@ describe("refs", () => {
114114 expect . assertions ( 2 ) ;
115115 expect ( await render ( element ) ) . toStrictEqual ( "Foo" ) ;
116116 } ) ;
117+
118+ it ( "removes items from a container" , async ( ) => {
119+ const Custom = ( ) => {
120+ const [ show , setShow ] = React . useState ( false ) ;
121+
122+ React . useEffect ( ( ) => {
123+ setShow ( true ) ;
124+ } , [ show ] ) ;
125+
126+ return (
127+ < array >
128+ < value > 1</ value >
129+ { show && < value > 2</ value > }
130+ </ array >
131+ ) ;
132+ } ;
133+
134+ const element = < Custom /> ;
135+
136+ expect ( await render ( element ) ) . toStrictEqual ( [ "1" , "2" ] ) ;
137+ } ) ;
117138} ) ;
Original file line number Diff line number Diff line change @@ -85,6 +85,32 @@ function createInstance<T extends keyof JsonElements>(
8585 }
8686}
8787
88+ /** remove a child from the node */
89+ function removeChild ( parent : JsonNode , child : JsonNode ) {
90+ switch ( parent . type ) {
91+ case "array" :
92+ parent . items = parent . items . filter ( ( c ) => c !== child ) ;
93+ break ;
94+
95+ case "object" :
96+ parent . properties = parent . properties . filter ( ( c ) => c !== child ) ;
97+ break ;
98+
99+ case "property" :
100+ if ( parent . valueNode === child ) {
101+ parent . valueNode = undefined ;
102+ }
103+
104+ break ;
105+ case "value" :
106+ parent . items = parent . items . filter ( ( c ) => c !== child ) as any ;
107+
108+ break ;
109+ default :
110+ throw new Error ( "Unknown type" ) ;
111+ }
112+ }
113+
88114export const hostConfig : HostConfig <
89115 keyof JsonElements ,
90116 any ,
@@ -119,7 +145,8 @@ export const hostConfig: HostConfig<
119145 } ,
120146
121147 clearContainer : ( parent : JsonNode ) => { } ,
122-
148+ removeChildFromContainer : removeChild ,
149+ removeChild,
123150 finalizeInitialChildren : ( ) => false ,
124151 prepareUpdate : ( ) => null ,
125152 shouldSetTextContent : ( ) => false ,
You can’t perform that action at this time.
0 commit comments