Giter Club home page Giter Club logo

menhera's Introduction

Menhera

an experimental lovely framework

Install

yarn add menhera

Example

const Mhr = require('menhera').default
const {EventEmitter} = require('events')

const event = new EventEmitter()

Mhr.use({
  $on: {
    $V({_key, _val}) {
      event.on(_key, () => {
        console.log(_val)
      })
    },
    $F({_key, _val}) {
      event.on(_key, _val)
    },
    $O({_key, _val}) {
      for (let [k, v] of Object.entries(_val)) {
        event.on(_key, v)
      }
    },
    $A({_key, _val}) {
      _val.forEach(fn => {
        event.on(_key, fn)
      })
    }
  },
  on: {
    test0: 'test0',
    test1() {
      console.log('test1')
    },
    test2: {
      foo() {
        console.log('test2.foo')
      },
      bar() {
        console.log('test2.bar')
      }
    },
    test3: [
      () => {
        console.log('test3.0')
      },
      () => {
        console.log('test3.1')
      }
    ]
  }
})

event.emit('test0')
event.emit('test1')
event.emit('test2')
event.emit('test3')

// test0
// test1
// test2.foo
// test2.bar
// test3.0
// test3.1

menhera's People

Contributors

uu-z avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

menhera's Issues

plugins: alias

Mhr.$use({
  plugins:{alias},
  alias: {
    $use: 'use',
    $unuse: 'unuse'
  }
})

Mhr.use({})
Mhr.unuse({})

$unuse support

let a = {
  _hooks: {
    foo: {
      bar: ({ _val }) => console.log(_val)
    }
  }
};

Mhr.$use(a);
Mhr.$use({
  "foo.bar": "hello world"
});
// should print"hello world"

Mhr.$unuse(a);
Mhr.$use({
  "foo.bar": "hello world"
});
// should not work

feature: _hooks alias

Mhr.$use({
  _hooks: {
    foo: {
      bar: () => {}
    }
  }
});

||

Mhr.$use({
  $foo: {
    bar: () => {}
  }
});

||

Mhr.$use({
  "$foo.bar": () => {}
});

||

Mhr.$use({
  "$foo/bar": () => {}
});

feature: @decorators property

version1

Mhr.$use({
  'proxy@testFloat': {
    get() {},
    set() {}
  },
  'ui@testFloat': {
    displayName: 'customName',
    Category: 'Config.custom',
    editable: true,
    showable: true,
    globalConfig: true,
    minValue: 0,
    maxValue: 10
  },
  'type@testFloat': {
    private: false,
    const: false,
    type: 'float'
  },
  testFloat: 5
})

meta hook supprt

Mhr.$use({
  __routes: {enable: true,foo: "bar"},
  routes: {
    "get /": {
      auth: ["admin"],
      handler: ctx => {}
    }
  }
});

complier configable

Mhr.$use({
  __config:{
    $: {
      compiledTo: "_hooks",
    },
    __: {
      compiledTo: "_metas",
    }
  }
})

middleware hook support

const add = ({ _val, next }) => {
  _val++;
  next();
};
const log = ({ _val }) => {
  console.log(_val);
};

Mhr.$use({
  _hooks: {
    foo: {
      bar: [add, add, log]
    }
  },
  foo: {
    bar: 0
  }
});

feature: pattern matching

let s = console.log;
let c = () => {
  let uuid = "";
  /*
    implement
  */
  return uuid;
};

Mhr.$use({
  _hooks: {
    foo: {
      bar: {
        [c(0)]: () => s("Zero"),
        [c(true)]: () => s("True"),
        [c(null)]: () => s("Null"),
        [c(a, b, c)]: (a, b, c) => s(`got ${a} ${b} ${c}`),
        [c({ valid: true, name: String })]: ({ name }) =>
          s("when valid, my name is ${name}"),
        _: () => s("Unknown")
      }
    }
  }
});

Mhr.$use([
  {
    "foo.bar": 0
  },
  {
    "foo.bar": true
  },
  {
    "foo.bar": null
  },
  {
    "foo.bar": [1, 2, 3]
  },
  {
    "foo.bar": {
      valid: true,
      name: "menhera"
    }
  }
]);

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.