DeloitteAU / react-habitat

⚛️ 🛅 A React DOM Bootstrapper designed to harmonise a hybrid 'CMS + React' application.
Other
262 stars 42 forks source link

added Bootstrapper.destroyHabitats method #23

Closed finnfiddle closed 6 years ago

finnfiddle commented 6 years ago

I am quite possibly doing something wrong but I found that my components on different pages of my PHP app were not being unmounted when changing pages. Using this.dispose() was removing the Bootstrapper as well so I couldnt manually unload the mounted components so I had to hack it like this:

class MyApp extends Bootstrapper {
  constructor() {
    super();
  }

  cleanUp() {
    // Get open habitats for this container
    const habitats = Habitat.listHabitats(this.__container__.id);
    // Clean up
    for (let i = 0; i < habitats.length; ++i) {
      this.__container__.factory.dispose(habitats[i]);
      Habitat.destroy(habitats[i]);
    }
  }
}

Which seemed to fixed my problem. And I thought this might be useful for others too to be included in the API.

jennasalau commented 6 years ago

Hey Finn,

I think this is a great idea!.. I just feel funny about the name "destroy" as this feels very catastrophic to the users.

What if we change destroyHabitats to unmountHabitats? I think unmount sounds better and also kinda explains what will happen.

Let me know what you think.

finnfiddle commented 6 years ago

sounds reasonable - I made the change

jennasalau commented 6 years ago

This is now available in v0.6.0