Code Monkey home page Code Monkey logo

isequal's People

Contributors

chilingling avatar yanhaijing avatar yugasun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

isequal's Issues

关于中间件的讨论

对更多类型支持,这些类型不太常用,可以通过中间件的方式提供,比如函数,arraybuffer,dom等

function functionMiddleware(opt) {
    return (value, other, next) => {
        if (typeof value === 'function' && typeof other === 'function') {
            return value.name === other.name
        }
        return next(value, other, next)
    }
}

isEqual(a, b, functionMiddleware())

更希望的方式是多个中间件可以组合

import { compose } from '@jsmini/functional';

function functionMiddleware1(opt) {
    return next => (value, other) => {
        if (typeof value === 'function' && typeof other === 'function') {
            return value.name === other.name
        }
        return next(value, other, next)
    }
}

function functionMiddleware2(opt) {
    return next => (value, other) => {
        if (typeof value === 'function' && typeof other === 'function') {
            return value.name === other.name
        }
        return next(value, other, next)
    }
}

isEqual(a, b, functionMiddleware1()) // 单个
isEqual(a, b, compose(functionMiddleware1(), functionMiddleware2())) // 多个

function isEqual(value, other, enhancer) {
  // ...
  if(type(enhancer) === 'function') {
        const res = enhancer(value, other, next);
        // 兼容两种调用方式
        return typeof res === 'function' ?  enhancer(next)(value, other) : res;
  }
  // ...
}

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.