1.3.1 • Published 7 years ago

glaive v1.3.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Glaive

Trying to build a new dependency module Injector

Travis Coverage Status npm npm npm

Features

  • Overall process async dependency module
  • After/before inject process
  • Functional inject & decorator inject
  • Custom Injector
  • Implement module initialization lifecycle
  • Inheritance of module
  • Inheritance of module injector
  • Override of module injector
  • Merge options for value provider
  • Custom options distribute to module
  • Custom rule distribute to dependency module
  • Custom distribute module name to dependency module
  • Before injection use preInject
  • Commons mount Params use mountParams
  • dependency Module preDistribute

Usage

yarn add glaive // or `npm install --save glaive`

Example

import { Injector as getInjector, Module, Decorator } from "glaive"

const Injector = getInjector(class BaseModule {})

class Call extends Module {}

@Decorator({
  deps: ["Environment"],
  after: environment => {
    console.log(environment)
  },
})
class NetWork extends Module {}

class HighSpeedNetWork extends NetWork {}

class Environment extends Module {
  constructor(...args){
    super(...args)
    this.system = 'ios'
  }
}

class Storage extends Module {
  constructor(...args) {
    super(...args)
  }
  async initialize() {
    await new Promise(resolve=>setTimeout(resolve, 0))
  }
}

// All aysnc functions support sync.

class Phone extends Injector {
  constructor(...args) {
    super(...args)
    this.inject([
        {
          module: Environment,
          key: "env"
        },
        {
          module: Storage,
          deps: ['Environment'],
          before: async (environment,storage) => {
            console.log(environment,storage)
            await new Promise(resolve=>setTimeout(resolve, 0))
          }
        },
        {
          module: NetWork,
        },
        {
          module: Call,
          deps: ['Environment','Storage','NetWork'],
          after: async () => {
            await new Promise(resolve=>setTimeout(resolve, 0)) // this time is after call init.
          }
        }
      ])
  }
}

class Mobile extends Phone {
    constructor(...args){
      super(...args)
      this.inject([
        {
          module: HighSpeedNetWork,
          key: '$_HighSpeedNetWork',
          deps: ['Storage']
        }
      ])
    }
}

const mobile = new Mobile({
  state: 'CN',
  done: done => {
    console.log('\n')
    console.log(`done is ${done}!\n`, mobile)
  },
})
1.3.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago