我正在寻找一种优雅的方式来导入所有命名的导出,而不必导入默认值.
在一个文件中,我输出了许多命名常量和一个默认值:
// myModule.js
const myDefault = 'my default'
export const named1 = 'named1'
export const named2 = 'named2'
// many more named exports - otherwise this would not be an issue...
export default myDefault
Run Code Online (Sandbox Code Playgroud)
在另一个文件我想有一个优雅的方式来导入所有命名的出口只,而无需导入默认:
// anotherFile.js
// this is what I would like to do, but syntax is not supported, right?
import { * as namedOnly } from './myModule'
Run Code Online (Sandbox Code Playgroud)
我不希望:
// anotherFile.js
import myDefault, * as namedOnly from './myModule'
Run Code Online (Sandbox Code Playgroud)
因为我不需要默认输入anotherFile.js,我的linting工具会让我对定义但未使用的内容感到不满myDefault.我也不想: …
我redux-observable与一起使用isomorphic-fetch来处理我的React应用程序中的http请求。与使用rxjs'相比ajax,我更喜欢这种组合,因为我正在测试Jest-可以在Node.js- 中运行测试,并希望使用来拦截http请求nock。参见以下相关问题:使用fetch代替redux-observable的ajax。
这就是问题所在:我感到UnhandledPromiseRejectionWarning恐惧:DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.因为我不是直接兑现我的诺言拒绝,而是将其留给了可观察者:
// apiModule.js
import fetch from 'isomorphic-fetch'
const api = {
getSomething: () => {
const request = fetch('http://some-api/')
.then(res => catchError(res)) // throwing an Error here if not response.ok
.then(res => res.json())
return …Run Code Online (Sandbox Code Playgroud)