Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问可以使用rxjs吗? #308

Closed
dearhulu opened this issue Aug 7, 2017 · 13 comments
Closed

请问可以使用rxjs吗? #308

dearhulu opened this issue Aug 7, 2017 · 13 comments

Comments

@dearhulu
Copy link

dearhulu commented Aug 7, 2017

使用wepy后,小程序是否可以使用rxjs?
尝试后会报 Uncaught TypeError: Cannot read property 'assign' of undefined 的错误

@Gcaufy
Copy link
Collaborator

Gcaufy commented Aug 7, 2017

理论上是不会有问题的。

@dearhulu
Copy link
Author

dearhulu commented Aug 7, 2017

整体导入会报错 import Rx from 'rxjs/Rx';

只能以补丁方式导入
import { Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';

但这种方式遇到某些操作符interval, delay, debounce就会报错 root_1.root.setInterval is not a function;

@hejinzhi
Copy link
Contributor

hejinzhi commented Jan 2, 2018

@dearhulu 请问这个问题怎么解决,Thanks

@hejinzhi
Copy link
Contributor

hejinzhi commented Jan 2, 2018

@Gcaufy 同样的错误,报 Uncaught TypeError: Cannot read property 'assign' of undefined 的错误

@Gcaufy
Copy link
Collaborator

Gcaufy commented Jan 2, 2018

@Gcaufy Gcaufy closed this as completed Jan 2, 2018
@hejinzhi
Copy link
Contributor

hejinzhi commented Jan 2, 2018

@Gcaufy 不行喔,还是报同样的错误。wepy new demo,然后安装上面的步骤做还是一样
wepy.config.js的代码是这样对吧?

const path = require('path');
var prod = process.env.NODE_ENV === 'production'

module.exports = {
  wpyExt: '.wpy',
  build: {
    web: {
      htmlTemplate: path.join('src', 'index.template.html'),
      htmlOutput: path.join('web', 'index.html'),
      jsOutput: path.join('web', 'index.js')
    }
  },
  resolve: {
    alias: {
      counter: path.join(__dirname, 'src/components/counter'),
      '@': path.join(__dirname, 'src')
    },
    modules: ['node_modules']
  },
  eslint: true,
  compilers: {
    less: {
      compress: true
    },
    /*sass: {
      outputStyle: 'compressed'
    },*/
    babel: {
      sourceMap: true,
      presets: [
        'env'
      ],
      plugins: [
        'transform-class-properties',
        'transform-decorators-legacy',
        'transform-object-rest-spread',
        'transform-export-extensions',
      ]
    }
  },
  plugins: {},
  appConfig: {
    noPromiseAPI: ['createSelectorQuery']
  }
}

if (prod) {

  delete module.exports.compilers.babel.sourcesMap;
  // 压缩sass
  // module.exports.compilers['sass'] = {outputStyle: 'compressed'}

  // 压缩less
  module.exports.compilers['less'] = {
    compress: true
  }

  // 压缩js
  module.exports.plugins = {
    uglifyjs: {
      filter: /\.js$/,
      config: {}
    },
    imagemin: {
      filter: /\.(jpg|png|jpeg)$/,
      config: {
        jpg: {
          quality: 80
        },
        png: {
          quality: 80
        }
      }
    }
  }

}

module.exports.plugins = module.exports.plugins || {};

module.exports.plugins.replace = {
  filter: /rxjs[\\\/]util[\\\/].*\.js$/,
  config: {
    find: 'require(\'./root.js\')',
    replace: '{root:require(\'./../../wepy-async-function/global.js\')}'
  }
};

@Gcaufy
Copy link
Collaborator

Gcaufy commented Jan 3, 2018

@hejinzhi 查看一下npm/rxjs/util/assgin.js 代码。 中间的require('./root.js')' 是否还在。

@hejinzhi
Copy link
Contributor

hejinzhi commented Jan 3, 2018

@Gcaufy 存在,那个新增的replace方法好像没被调用?

"use strict";
var root_1 = require('./root.js');
function assignImpl(target) {
    var sources = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        sources[_i - 1] = arguments[_i];
    }
    var len = sources.length;
    for (var i = 0; i < len; i++) {
        var source = sources[i];
        for (var k in source) {
            if (source.hasOwnProperty(k)) {
                target[k] = source[k];
            }
        }
    }
    return target;
}
exports.assignImpl = assignImpl;
;
function getAssign(root) {
    return root.Object.assign || assignImpl;
}
exports.getAssign = getAssign;
exports.assign = getAssign(root_1.root);
//# sourceMappingURL=assign.js.map

@hejinzhi
Copy link
Contributor

hejinzhi commented Jan 3, 2018

正则是不是这样写才对

require\(\'./root.js\'\)

@Gcaufy
Copy link
Collaborator

Gcaufy commented Jan 3, 2018

@hejinzhi 那不是正则,那是一个string.

这里的代码是在我本地测试通过的。。。调用 replace插件之后,输出日志会输出

[17:29:38] [变更] JS  : dist\npm\rxjs\util\assign.js

@hejinzhi
Copy link
Contributor

hejinzhi commented Jan 3, 2018

@Gcaufy 可以了,但是debounceTime这些操作符不能用

root_1.root.setInterval is not a function;at pages/index page inputTyping function
TypeError: root_1.root.setInterval is not a function

@Gcaufy
Copy link
Collaborator

Gcaufy commented Jan 3, 2018

@hejinzhi
npm\rxjs\scheduler\AsyncAction.js 中还有一个 root.js 没有被修改,
使用相同的方法将其修改掉就可以了。

@g1mi
Copy link

g1mi commented Jan 17, 2018

@Gcaufy
https://github.com/Tencent/wepy/wiki/WePY%E9%A1%B9%E7%9B%AE%E4%B8%AD%E4%BD%BF%E7%94%A8RxJS
照这里的我试了一下,还是没有替换掉字符串,于是乎
我查看了一下wepy-plugin-replace 的工具包,把代码改了一下

module.exports.plugins = {
  'replace': {
    filter: /rxjs[\\\/]util[\\\/].*\.js$/,
    config: {
      find: 'require(\'./root.js\')',
      replace: '{root:require(\'./../../wepy-async-function/global.js\')}'
    }
  }
}

可是还是没有替换掉,log里面也没有“替换”

[编译] 入口: src/app.wpy
[21:10:06] [写入] JSON: dist/app.json
[21:10:06] [编译] 组件: src/components/counter.wpy
[21:10:06] [编译] 组件: src/components/group.wpy
[21:10:06] [编译] 组件: src/components/groupitem.wpy
[21:10:06] [编译] 组件: src/components/list.wpy
[21:10:06] [编译] 组件: src/components/panel.wpy
[21:10:06] [拷贝] HTML: src/index.template.html
[21:10:06] [编译] 页面: src/pages/index.wpy
[21:10:06] [写入] JSON: dist/pages/index.json
[21:10:06] [编译] 页面: src/pages/tutorial.wpy
[21:10:06] [写入] JSON: dist/pages/tutorial.json
[21:10:07] [写入] JS  : dist/app.js
[21:10:07] [写入] JS  : dist/components/counter.js
[21:10:07] [写入] JS  : dist/components/group.js
[21:10:07] [写入] JS  : dist/components/groupitem.js
[21:10:07] [写入] JS  : dist/components/list.js
[21:10:07] [写入] JS  : dist/components/panel.js
[21:10:07] [写入] JS  : dist/mixins/test.js
[21:10:07] [写入] WXML: dist/pages/index.wxml
[21:10:07] [写入] JS  : dist/pages/index.js
[21:10:07] [写入] WXML: dist/pages/tutorial.wxml
[21:10:07] [写入] JS  : dist/pages/tutorial.js
[21:10:07] [写入] WXSS: dist/app.wxss
[21:10:07] [写入] WXSS: dist/components/counter.wxss
[21:10:07] [写入] WXSS: dist/components/group.wxss
[21:10:07] [写入] WXSS: dist/components/groupitem.wxss
[21:10:07] [写入] WXSS: dist/components/list.wxss
[21:10:07] [写入] WXSS: dist/components/panel.wxss
[21:10:07] [写入] WXSS: dist/pages/index.wxss
[21:10:07] [写入] WXSS: dist/pages/tutorial.wxss

虽然可以手动改掉,但是我想知道为什么replace的plugin我这里会没作用呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants