Skip to content

RxJS 集成遇到root找不到function的问题 #794

@maimake

Description

@maimake

Description

我在尝试接入RxJS的时候发现几个问题

  1. 除了有require('./root')外,还有其他形式:
require('../util/root');
require('../../util/root');

可以通过以下命令查看所有引用root的文件

cd node_modules/rxjs
# or
cd dist/npm/rxjs
# find
grep -r "/root" --include \*.js * 
  1. 除了util目录下用到root,还有另外一些目录也有。同样可以通过以上命令查出来

  2. 在prod模式下,貌似require用的是双引号,而不是单引号。所以正则应该考虑下两种情况

module.exports.plugins.replace = {
  filter: /rxjs[\\/]util[\\/].*\.js$/,
  config: {
    find: /require\(['"]\.\/root.js['"]\)/,
    replace: '{root:require(\'./../../wepy-async-function/global.js\')}'
  }
}
  1. 我想既用moment又用 rxjs,那么replace插件支持同时配置吗?请问如何写?

Environment

  • Platform: 开发者工具
  • Platform version: 2017.01.16 基础库更新(1.9.0)
  • Wechat version: 6.6.1
  • wepy-cli version: v1.6.0
  • wepy version: 1.6.0

Reproduce

  1. 启用promise
  2. 启用rxjs
  3. 写某些底层带有setInterval的rxjs代码

Observed Results

Possible Unhandled Promise Rejection: TypeError: root_1.root.setInterval is not a function
    at AsyncAction.requestAsyncId (AsyncAction.js:65)
    at AsyncAction.schedule (AsyncAction.js:60)
    at AsyncScheduler.Scheduler.schedule (Scheduler.js:43)
    at DelaySubscriber._schedule (delay.js:100)
    at DelaySubscriber.scheduleNotification (delay.js:112)
    at DelaySubscriber._next (delay.js:116)
    at DelaySubscriber.Subscriber.next (Subscriber.js:90)
    at ScalarObservable._subscribe (ScalarObservable.js:49)
    at ScalarObservable.Observable._trySubscribe (Observable.js:172)
    at ScalarObservable.Observable.subscribe (Observable.js:160)

Expected Results

正常运行不报错

Relevant Code / Logs

import Rx from 'rxjs/Rx'
  var o = Rx.Observable.of(1)
  var powersOfTwo = o
    .mapTo(1)
    .expand(x => Rx.Observable.of(2 * x).delay(1000))
    .take(10);
  powersOfTwo.subscribe(x => console.log(x));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions