Skip to content

Instantly share code, notes, and snippets.

@terrierscript
Last active July 18, 2016 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrierscript/3c470528f0d2380da9a6bb0dcd073112 to your computer and use it in GitHub Desktop.
Save terrierscript/3c470528f0d2380da9a6bb0dcd073112 to your computer and use it in GitHub Desktop.
Recompose でいい感じに Higher-order Components(HoCs)を作る ref: http://qiita.com/inuscript/items/275dc41d0705f63ba95f
export const NotSupportedMessage = () => <h3>お使いのブラウザはサポートされておりません</h3>
export default class MainApp extends Component{
isSupportedPlatform(){
if(/*ブラウザが未サポートかの判定*/){
return false
}
return true
}
render() {
if(!this.isSupportedPlatform()){
return <NotSupportedMessage />
}
return (
<div className="SomeApp">
何らかのアプリケーション
</div>
)
}
}
export const NotSupportedMessage = () => <h3>お使いのブラウザはサポートされておりません</h3>
export default class MainApp extends Component{
isSupportedPlatform(){
if(/*ブラウザが未サポートかの判定*/){
return false
}
return true
}
render() {
if(!this.isSupportedPlatform()){
return <NotSupportedMessage />
}
return (
<div className="SomeApp">
何らかのアプリケーション
</div>
)
}
}
import branch from 'recompose/branch'
import renderComponent from 'recompose/renderComponent'
// branchは、下記のように引数を取る
// branch(判定関数, trueの時, falseの時)
const NotSupportedMessage = () => <h3>お使いのブラウザはサポートされておりません</h3>
const SomeMyApp = () => (
<div className="SomeApp">
何らかのアプリケーション
</div>
)
const isSupportedBrowser = () => {
if(/*ブラウザが未サポートかの判定*/){
return false
}
return true
}
const withBrowserCheck = branch(
isSupportedBrowser,
component => component, // trueの時は、受け取っていた引数をそのまま流用
renderComponent(NotSupportedMessage)
)
const MainApp = withBrowserCheck(SomeMyApp)
import branch from 'recompose/branch'
import renderComponent from 'recompose/renderComponent'
// branchは、下記のように引数を取る
// branch(判定関数, trueの時, falseの時)
const NotSupportedMessage = () => <h3>お使いのブラウザはサポートされておりません</h3>
const SomeMyApp = () => (
<div className="SomeApp">
何らかのアプリケーション
</div>
)
const isSupportedBrowser = () => {
if(/*ブラウザが未サポートかの判定*/){
return false
}
return true
}
const withBrowserCheck = branch(
isSupportedBrowser,
component => component, // trueの時は、受け取っていた引数をそのまま流用
renderComponent(NotSupportedMessage)
)
const MainApp = withBrowserCheck(SomeMyApp)
const MainApp = compose(withBrowserCheck, withDeviceCheck)(SomeMyApp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment