Skip to content

Commit

Permalink
fluxible-router: remove decorator support (#657)
Browse files Browse the repository at this point in the history
Co-authored-by: Pablo Palacios <[email protected]>
  • Loading branch information
pablopalacios and pablopalacios authored Oct 4, 2020
1 parent dfe6d73 commit b041bcc
Show file tree
Hide file tree
Showing 6 changed files with 472 additions and 580 deletions.
27 changes: 0 additions & 27 deletions packages/fluxible-router/docs/api/handleHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,6 @@ AppComponent = provideContext(AppComponent);
module.exports = AppComponent;
```

### Decorator Usage

***Decorators are an evolving proposal and should be used with caution
as the API may change at any point. Decorator support in
fluxible-addons-react was built against Babel 5's implementation of
decorators. As of Babel 6, support for decorators has been removed although
third party transforms have been attempted with limited success.

Decorators are also only proposed for classes and properties and therefore
will not work with stateless functional components. See
[decorator pattern](https://github.com/wycats/javascript-decorators) for
more information on the proposal.***

```js
// components/App.jsx
import {provideContext} from 'fluxible-addons-react';
import {handleHistory} from 'fluxible-router';

@provideContext
@handleHistory
class AppComponent extends React.Component {
//...
}

export default AppComponent;
```

## onbeforeunload Support

The `History` API does not allow `popstate` events to be cancelled, which results in `window.onbeforeunload()` methods not being triggered. This is problematic for users, since application state could be lost when they navigate to a certain page without knowing the consequences.
Expand Down
26 changes: 0 additions & 26 deletions packages/fluxible-router/docs/api/handleRoute.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,3 @@ MyComponent = handleRoute(MyComponent);

module.exports = MyComponent;
```

### Decorator Usage

***Decorators are an evolving proposal and should be used with caution
as the API may change at any point. Decorator support in
fluxible-addons-react was built against Babel 5's implementation of
decorators. As of Babel 6, support for decorators has been removed although
third party transforms have been attempted with limited success.

Decorators are also only proposed for classes and properties and therefore
will not work with stateless functional components. See
[decorator pattern](https://github.com/wycats/javascript-decorators) for
more information on the proposal.***

```js
// components/App.jsx
import {provideContext} from 'fluxible-addons-react';
import {handleHistory} from 'fluxible-router';

@handleRoute
class MyComponent extends React.Component {
//...
}

export default MyComponent;
```
8 changes: 0 additions & 8 deletions packages/fluxible-router/src/lib/handleHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,5 @@ function createComponent(Component, opts) {
* @returns {React.Component}
*/
module.exports = function handleHistory(Component, opts) {
// support decorator pattern
if (arguments.length === 0 || typeof arguments[0] !== 'function') {
opts = arguments[0];
return function handleHistoryDecorator(componentToDecorate) {
return createComponent(componentToDecorate, opts);
};
}

return createComponent.apply(null, arguments);
};
7 changes: 0 additions & 7 deletions packages/fluxible-router/src/lib/handleRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,5 @@ function createComponent(Component) {
}

module.exports = function handleRoute(Component) {
// support decorator pattern
if (arguments.length === 0) {
return function handleRouteDecorator(componentToDecorate) {
return createComponent(componentToDecorate);
};
}

return createComponent.apply(null, arguments);
};
27 changes: 0 additions & 27 deletions packages/fluxible-router/tests/mocks/MockAppComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,3 @@ module.exports = provideContext(handleHistory(MockAppComponent, {
module.exports.createWrappedMockAppComponent = function createWrappedMockAppComponent(opts) {
return provideContext(handleHistory(MockAppComponent, opts), customContextTypes);
};

module.exports.createDecoratedMockAppComponent = function createDecoratedMockAppComponent(opts) {
@provideContext
@handleHistory(opts)
class DecoratedMockAppComponent extends React.Component {
static contextTypes = {
getStore: PropTypes.func.isRequired
};
static propTypes = {
children: PropTypes.object,
currentRoute: PropTypes.object
};
constructor(props, context) {
super(props, context);
}
render() {
if (!this.props.children) {
return null;
}
return React.cloneElement(this.props.children, {
currentRoute: this.props.currentRoute
});
}
}

return DecoratedMockAppComponent;
};
Loading

0 comments on commit b041bcc

Please sign in to comment.