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 集成遇到root找不到function的问题 #794

Closed
maimake opened this issue Jan 18, 2018 · 3 comments
Closed

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

maimake opened this issue Jan 18, 2018 · 3 comments

Comments

@maimake
Copy link

maimake commented Jan 18, 2018

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));
@maimake maimake changed the title RxJS RxJS 集成遇到root找不到function的问题 Jan 18, 2018
@maimake
Copy link
Author

maimake commented Jan 18, 2018

原来replace插件是支持数组的。👍

我目前把配置改成如下之后,就能畅玩RxJS了:

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

@Gcaufy
Copy link
Collaborator

Gcaufy commented Jan 19, 2018

#308

@Gcaufy Gcaufy closed this as completed Jan 19, 2018
@shiran1992
Copy link

麻烦我想问一下,如果我想在编译的时候将console.log()这种形式的东西替换空字符串,正则应该怎么写啊?拜托

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

3 participants