Giter VIP home page Giter VIP logo

react-dl's Introduction

react-dl

声明式 react 组件,消除 jsx 中的三目运算符和逻辑守卫!!灵感来自 angular 和 vue 的指令。

在线例子🌰🌰🌰🌰🌰🌰🌰🌰

https://followwinter.github.io/react-dl

特性

  • 🎉 解决在 jsx 中编写三目运算符导致的层层逻辑嵌套,让逻辑归逻辑,布局归布局
  • 🎉 解决封装泄漏,提高项目可维护性

组件

  • 🎉 Show:显示一个组件
  • 🚧 Switch/Case:根据条件显示一个组件

TODO 列表

  • 🚧 优化文档
  • 🚧 优化组件和示例

安装指令

$ npm install --save @followwinter/react-dl-show
$ npm install --save @followwinter/react-dl-switch

使用前

render(){
    return (
        isEdit?(
              <div>
                  {
                      hasWrite?(
                          <button>编辑</button>
                      ):(
                          <button>查看</button>
                      )
                  }
              </div>
          ):(
              <div>
                  {isOnline?(
                      <button>下线</button>
                  ):(
                      <button>上线</button>
                  )}
              </div>
          )
    )
}

使用后

isShow = (show) => ({children}) => <Show test={show} > {children} </Show>

render(){
    const InEdit = isShow(isEdit)
    const InDetail = isShow(!isEdit)
    
    const HasWrite = isShow(hasWrite)
    const NotHasWrite= isShow(!hasWrite)
    
    const Online= isShow(online)
    const Offline= isShow(!online)
    
    return (
        <div>
            <InEdit>
                <HasWrite>
                    <button>编辑</button>
                </HasWrite>
                <NotHasWrite>
                    <button>查看</button>
                </NotHasWrite>
            </InEdit>
            <InDetail>
                <Online>
                    <button>下线</button>
                </Online>
                <Offline>
                    <button>下线</button>
                </Offline>
            </InDetail>
         </div>
    )
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.