File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -131,8 +131,6 @@ export class World {
131
131
destroyEntity ( this , this [ $internal ] . worldEntity ) ;
132
132
this [ $internal ] . worldEntity = null ! ;
133
133
134
- // Destroy itself and all entities.
135
- this . entities . forEach ( ( entity ) => destroyEntity ( this , entity ) ) ;
136
134
this . reset ( ) ;
137
135
this . #isInitialized = false ;
138
136
Original file line number Diff line number Diff line change @@ -49,6 +49,22 @@ describe('World', () => {
49
49
expect ( world . entities . length ) . toBe ( 1 ) ;
50
50
} ) ;
51
51
52
+ it ( 'destroy should lead to entities with auto-remove relations being removed as well' , ( ) => {
53
+ const Node = trait ( ) ;
54
+ const ChildOf = relation ( { autoRemoveTarget : true , exclusive : true } ) ;
55
+
56
+ const world = createWorld ( ) ;
57
+
58
+ // Create a parent node and two child nodes
59
+ const parentNode = world . spawn ( Node ) ;
60
+ world . spawn ( Node , ChildOf ( parentNode ) ) ;
61
+ world . spawn ( Node , ChildOf ( parentNode ) ) ;
62
+
63
+ // Expect this to not throw, since the ChildOf relation will automatically
64
+ // remove the child node when the parent node is destroyed first
65
+ expect ( ( ) => world . destroy ( ) ) . not . toThrow ( ) ;
66
+ } ) ;
67
+
52
68
it ( 'errors if more than 16 worlds are created' , ( ) => {
53
69
for ( let i = 0 ; i < 16 ; i ++ ) {
54
70
createWorld ( ) ;
Original file line number Diff line number Diff line change @@ -42,6 +42,22 @@ describe('World', () => {
42
42
expect ( world . entities . length ) . toBe ( 1 ) ;
43
43
} ) ;
44
44
45
+ it ( 'destroy should lead to entities with auto-remove relations being removed as well' , ( ) => {
46
+ const Node = trait ( ) ;
47
+ const ChildOf = relation ( { autoRemoveTarget : true , exclusive : true } ) ;
48
+
49
+ const world = createWorld ( ) ;
50
+
51
+ // Create a parent node and two child nodes
52
+ const parentNode = world . spawn ( Node ) ;
53
+ world . spawn ( Node , ChildOf ( parentNode ) ) ;
54
+ world . spawn ( Node , ChildOf ( parentNode ) ) ;
55
+
56
+ // Expect this to not throw, since the ChildOf relation will automatically
57
+ // remove the child node when the parent node is destroyed first
58
+ expect ( ( ) => world . destroy ( ) ) . not . toThrow ( ) ;
59
+ } ) ;
60
+
45
61
it ( 'errors if more than 16 worlds are created' , ( ) => {
46
62
for ( let i = 0 ; i < 16 ; i ++ ) {
47
63
createWorld ( ) ;
You can’t perform that action at this time.
0 commit comments