3939
4040local function newTemplate (roact : any , unpureByDefault : boolean ? )
4141 type CleanupMethod = () -> ()
42- type UpdateMethod <Props> = (props : Props ) -> ()
42+ type UpdateMethod <Props> = (props : Props ) -> CleanupMethod
4343 type Constructor <Props> = (
4444 name : string ,
4545 parent : Instance ,
@@ -63,20 +63,28 @@ local function newTemplate(roact: any, unpureByDefault: boolean?)
6363 end
6464 end
6565 self .updateCallbacks = {}
66+ self .updateCleanups = {}
6667 self .cleanup = f (hostKey , hostParent , function (callback )
67- callback (self .props )
68+ table.insert ( self . updateCleanups , callback (self .props ) )
6869 table.insert (self .updateCallbacks , f )
6970 end )
7071 end
7172 function Component :render ()
7273 return roact .createFragment ()
7374 end
7475 function Component :didUpdate ()
76+ for _ , cleanup in self .updateCleanups do
77+ cleanup ()
78+ end
79+ self .updateCleanups = {}
7580 for _ , callback in self .updateCallbacks do
76- callback (self .props )
81+ table.insert ( self . updateCleanups , callback (self .props ) )
7782 end
7883 end
7984 function Component :willUnmount ()
85+ for _ , cleanup in self .updateCleanups do
86+ cleanup ()
87+ end
8088 self .cleanup ()
8189 end
8290 return function (props : Props , children )
0 commit comments