Skip to content

Commit

Permalink
Merge pull request #24 from DeloitteDigitalAPAC/develop
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
jennasalau authored Oct 14, 2017
2 parents 1fcb50a + a35908e commit 963a5de
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## React Habitat Change log

### [0.6.0]

- Added "unmountHabitats" method and lifecycle hooks. Thanks @finnfiddle

### [0.5.1]

- Updated support for React and React DOM v16. Thanks @nilsml
Expand Down
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# React Habitat ![Build Status](https://travis-ci.org/DeloitteDigitalAPAC/react-habitat.svg?branch=master)

🌟 v0.5 Released! See [whats new](https://github.com/DeloitteDigitalAPAC/react-habitat/blob/master/CHANGELOG.md#050).

If you are on v0.4, Please read [v0.4 to v0.5 migration guide](https://github.com/DeloitteDigitalAPAC/react-habitat/wiki/v0.4-to-v0.5-Migration-Guide). While there are *zero* breaking changes in this release we are moving closer to the official v1 API and we want you up to date.

> *Looking for the [v0.4 docs](https://github.com/DeloitteDigitalAPAC/react-habitat/tree/4e82be35a1d9b5f2c95d7957f277dbbd1ca89b64#react-habitat-)?*
Expand Down Expand Up @@ -73,7 +71,8 @@ However, you are definitely invited to use it if you want to.
- [Controlling Scope and Lifetime](#controlling-scope-and-lifetime)
- [Changing the habitat query selector](#changing-the-habitat-query-selector)
- [Dynamic updates](#dynamic-updates)
- [Update lifecycle](#update-lifecycle)
- [Bootstrapper lifecycle events](#bootstrapper-lifecycle-events)
- [Unmount react habitats](#unmount-react-habitats)
- [Disposing the container](#disposing-the-container)
- [Examples](https://github.com/DeloitteDigitalAPAC/react-habitat/tree/master/examples)
- [Contribute](#want-to-contribute)
Expand Down Expand Up @@ -765,16 +764,21 @@ window.updateHabitat();

**[⬆ back to top](#table-of-contents)**

### Update Lifecycle
### Bootstrapper Lifecycle Events

`ReactHabitat.Bootstrapper` has update "lifecycle methods" that you can override to run code at particular times
in the process. An update is the event that occurs when registrations are resolved.
`ReactHabitat.Bootstrapper` has "lifecycle methods" that you can override to run code at particular times
in the process.

|Method|Description
|---|---
|`shouldUpdate(node)`|Called when an update has been requested. Return false to cancel the update.
|`willUpdate(node)`|Called when an update is about to take place.
|`didUpdate(node)`|Called after an update has taken place.
|`willUnmountHabitats()`|Called when all active React Habitats are about to be unmounted.
|`didUnmountHabitats()`|Called after all active React Habitats have been unmounted.
|`didDispose()`|Called after all active React Habitats have been unmounted and the container released.

> An "update" is the event when registrations are resolved and a React mount will/did occur.
Example

Expand All @@ -799,6 +803,26 @@ class MyApp extends ReactHabitat.Bootstrapper {

**[⬆ back to top](#table-of-contents)**

### Unmount React Habitats

To unmount all React Habitat instances. Call the `unmountHabitats()` method.

Example

```javascript
class MyApp extends ReactHabitat.Bootstrapper {
constructor(){
super();

//...

this.unmountHabitats();
}
}
```

**[⬆ back to top](#table-of-contents)**

### Disposing the container

To unload the container and remove all React Habitat instances. Call the `dispose()` method.
Expand Down
68 changes: 60 additions & 8 deletions dist/react-habitat.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,21 @@ return /******/ (function(modules) { // webpackBootstrap
}

/**
* Dispose the container and destroy habitat instances
* Unmount all habitat instances for the container
* @param {function} [cb=null] - Optional callback
*/

}, {
key: 'dispose',
value: function dispose() {
key: 'unmountHabitats',
value: function unmountHabitats() {
var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;


// Lifecycle event
if (typeof this.willUnmountHabitats === 'function') {
this.willUnmountHabitats();
}

// Get open habitats for this container
var habitats = _Habitat2.default.listHabitats(this.__container__.id);

Expand All @@ -462,17 +467,40 @@ return /******/ (function(modules) { // webpackBootstrap
_Habitat2.default.destroy(habitats[i]);
}

// Reset and release
this.__container__ = null;

// Lifecycle event
if (typeof this.didDispose === 'function') {
this.didDispose();
if (typeof this.didUnmountHabitats === 'function') {
this.didUnmountHabitats();
}

// Handle callback
_callback(cb, this);
}

/**
* Dispose the container and destroy habitat instances
* @param {function} [cb=null] - Optional callback
*/

}, {
key: 'dispose',
value: function dispose() {
var _this4 = this;

var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;

this.unmountHabitats(function () {
// Reset and release
_this4.__container__ = null;

// Lifecycle event
if (typeof _this4.didDispose === 'function') {
_this4.didDispose();
}

// Handle callback
_callback(cb, _this4);
});
}
}, {
key: 'container',
get: function get() {
Expand Down Expand Up @@ -1498,6 +1526,9 @@ return /******/ (function(modules) { // webpackBootstrap
_this._shouldUpdateProxy = spec.shouldUpdate || null;
_this._willUpdateProxy = spec.willUpdate || null;
_this._didUpdateProxy = spec.didUpdate || null;
_this._willUnmountProxy = spec.willUnmountHabitats || null;
_this._didUnmountProxy = spec.didUnmountHabitats || null;
_this._didDisposeProxy = spec.didDispose || null;

// Finally, set the container
_this.setContainer(containerBuilder.build(), function () {
Expand Down Expand Up @@ -1529,6 +1560,27 @@ return /******/ (function(modules) { // webpackBootstrap
this._didUpdateProxy();
}
}
}, {
key: 'willUnmountHabitats',
value: function willUnmountHabitats() {
if (this._willUnmountProxy) {
this._willUnmountProxy();
}
}
}, {
key: 'didUnmountHabitats',
value: function didUnmountHabitats() {
if (this._didUnmountProxy) {
this._didUnmountProxy();
}
}
}, {
key: 'didDispose',
value: function didDispose() {
if (this._didDisposeProxy) {
this._didDisposeProxy();
}
}
}]);

return _Mixin;
Expand Down
2 changes: 1 addition & 1 deletion dist/react-habitat.min.js

Large diffs are not rendered by default.

44 changes: 36 additions & 8 deletions lib/Bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,21 @@ var Bootstrapper = function () {
}

/**
* Dispose the container and destroy habitat instances
* Unmount all habitat instances for the container
* @param {function} [cb=null] - Optional callback
*/

}, {
key: 'dispose',
value: function dispose() {
key: 'unmountHabitats',
value: function unmountHabitats() {
var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;


// Lifecycle event
if (typeof this.willUnmountHabitats === 'function') {
this.willUnmountHabitats();
}

// Get open habitats for this container
var habitats = _Habitat2.default.listHabitats(this.__container__.id);

Expand All @@ -259,17 +264,40 @@ var Bootstrapper = function () {
_Habitat2.default.destroy(habitats[i]);
}

// Reset and release
this.__container__ = null;

// Lifecycle event
if (typeof this.didDispose === 'function') {
this.didDispose();
if (typeof this.didUnmountHabitats === 'function') {
this.didUnmountHabitats();
}

// Handle callback
_callback(cb, this);
}

/**
* Dispose the container and destroy habitat instances
* @param {function} [cb=null] - Optional callback
*/

}, {
key: 'dispose',
value: function dispose() {
var _this4 = this;

var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;

this.unmountHabitats(function () {
// Reset and release
_this4.__container__ = null;

// Lifecycle event
if (typeof _this4.didDispose === 'function') {
_this4.didDispose();
}

// Handle callback
_callback(cb, _this4);
});
}
}, {
key: 'container',
get: function get() {
Expand Down
24 changes: 24 additions & 0 deletions lib/classic/createBootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ var _Mixin = exports._Mixin = function (_Bootstrapper) {
_this._shouldUpdateProxy = spec.shouldUpdate || null;
_this._willUpdateProxy = spec.willUpdate || null;
_this._didUpdateProxy = spec.didUpdate || null;
_this._willUnmountProxy = spec.willUnmountHabitats || null;
_this._didUnmountProxy = spec.didUnmountHabitats || null;
_this._didDisposeProxy = spec.didDispose || null;

// Finally, set the container
_this.setContainer(containerBuilder.build(), function () {
Expand Down Expand Up @@ -121,6 +124,27 @@ var _Mixin = exports._Mixin = function (_Bootstrapper) {
this._didUpdateProxy();
}
}
}, {
key: 'willUnmountHabitats',
value: function willUnmountHabitats() {
if (this._willUnmountProxy) {
this._willUnmountProxy();
}
}
}, {
key: 'didUnmountHabitats',
value: function didUnmountHabitats() {
if (this._didUnmountProxy) {
this._didUnmountProxy();
}
}
}, {
key: 'didDispose',
value: function didDispose() {
if (this._didDisposeProxy) {
this._didDisposeProxy();
}
}
}]);

return _Mixin;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-habitat",
"version": "0.5.1",
"version": "0.6.0",
"description": "A React DOM Bootstrapper designed to harmonise a hybrid application",
"main": "./lib/index.js",
"repository": {
Expand Down
18 changes: 15 additions & 3 deletions readme-in-es5.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function MyApp() {
tag: 'div', // (Optional)
className: 'myHabitat', // (Optional)
replaceDisabled: false // (Optional)
}
},

// Create a new container (Required)
container: [
Expand All @@ -29,7 +29,7 @@ function MyApp() {
require.ensure(['./components/MyComponent'], () => {
resolve(require('./components/MyComponent'));
});
}
})
}
],

Expand All @@ -45,7 +45,19 @@ function MyApp() {

// Did update lifecycle event (Optional)
didUpdate: function(target) {
}
},

// Will unmount habitats lifecycle event (Optional)
willUnmountHabitats: function() {
},

// Did unmount habitats lifecycle event (Optional)
didUnmountHabitats: function() {
},

// Did dispose lifecycle event (Optional)
didDispose: function() {
},

});
}
Expand Down
Loading

0 comments on commit 963a5de

Please sign in to comment.