Nightly Panic Munchies

    @jswork/mixin-decorator

    1.0.0 • Public • Published

    mixin-decorator

    A decorator for mixins that doesn't overwrite existing methods.

    installation

    npm install @jswork/mixin-decorator

    usage

    • npm install
    import mixin from '@jswork/mixin-decorator';
    
    class A{
      static VERSION= '1.0';
      testA(){
        console.log('AAA')
      }
    }
    
    
    class B{
      static NAME ='BBB=NAME';
      testB(){
        console.log('BBB')
      }
    }
    
    @mixin(A,B)
    class MyClass(){
      static VERSION = '2.0';
      sayHi(){
        console.log('hi');
      }
    }
    
    let my =new MyClass();
    
    MyClass.VERSION; //2.0
    MyClass.NAME; //BBB=NAME
    
    my.testA(); //AAA
    my.testB(); //BBB

    support str import for webpack project:

    //OLD:
    module: {
        rules: [
          {
            test: /\.(js|jsx)$/,
            use: ['babel-loader'],
            exclude: /node_modules/,
          },
          //...
        ]
    }
    
    //NEW:
    module: {
        rules: [
          {
            test: /\.(js|jsx)$/,
            use: ['babel-loader'],
            include: [
              resolve(__dirname, "../src"),
              resolve(__dirname, "../node_modules/mixin-decorator")
            ]
          },
          //...
        ]
    }

    webpack resolve:(DO NOT USE .babelrc's resolve)

    import {resolve, join} from 'path';
    
    
    resolve: {
      extensions: ['.js', '.json', '.scss', '.css'],
      alias:{
        mixins: resolve(__dirname, '../src/components/mixins')
      }
    }

    todo list

    • [x] add @mixin(['on-chnage',obj ]) for plain object
    • [ ] NOT_SUPPORT add @mixin(['on-chnage',':node-module' ]) in npm
    • [ ] add unit test

    resources

    Install

    npm i @jswork/mixin-decorator

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    5.22 kB

    Total Files

    4

    Last publish

    Collaborators

    • afeiship