我正在尝试在一个新项目中设置Flow,但我的webpack解决路径令人困惑.我正在自动解析根文件夹,以便您可以使用components/Foo而不是../../../Components/Foo.
有没有解决的办法?我试过玩module.name_mapper= '^components/[a-zA-Z0-9$_]+$' -> 'src/components'但是没用.
src/pages/Login.js:5
5: import View from 'components/View';
^^^^^^^^^^^^^^^^^ components/View. Required module not found
Run Code Online (Sandbox Code Playgroud) 我有一个基于某些事件的 Observable,并且在某些时候会进行一些昂贵的计算。我想在多个不同的地方呈现该 Observable 的结果。如果我天真地在两个地方订阅这个 Observable,我最终会做两次昂贵的计算。这是一个代码片段,可以将我的观点带回家:
var s = new rx.Subject();
var o = s.map(x => { console.log('expensive computation'); return x });
o.subscribe(x => console.log('1: ' + x));
o.subscribe(x => console.log('2: ' + x));
s.next(42);
Run Code Online (Sandbox Code Playgroud)
输出是:
expensive computation
1: 42
expensive computation
2: 42
Run Code Online (Sandbox Code Playgroud)
我只想在地图中执行一次昂贵的计算。share实现了这一点,但它使迟到的订阅者无法获得要呈现的当前值。在之前的 RxJS 版本中,shareValue允许迟到的订阅者获取当前值。然而,这似乎shareBehavior在 RxJS 5 中被重命名,然后完全删除:
https://github.com/ReactiveX/rxjs/pull/588
https://github.com/ReactiveX/rxjs/pull/712
在这个问题上有一个很长的讨论,决定他们将“删除 shareBehavior 和 shareReplay 以防止用户混淆”。我不明白混淆的可能性是什么(所以也许这意味着我是这个决定拯救的用户之一?)。
publishBehavior看起来也很有希望,但我并不完全理解,publish而且它似乎增加了比我需要或想要的更多的复杂性。
无论如何,我想知道在 RxJS 5 中是否有推荐的方法来实现这一点。迁移文档没有提供任何建议。
我有各种React组件,当传入不同的道具时可以有不同的功能.通常我遇到一些分支逻辑,如果prop1存在,做一件事,但如果prop2存在则做其他事情.
一个示例可以是具有带有不同参数的输入的元素的两个更改处理程序.
有没有办法在Flowjs中指定需要两个处理程序之一?
有人可以给我一些建议或链接来讨论我是否应该为后端捆绑 JS?
我尝试用这个标题(和类似的词)搜索谷歌,但找不到任何有用的链接。
只是想知道,假设我正在使用最新的 Node.JS(es6-ready),我应该捆绑/编译 JS 吗?如果没有,我该如何使用打字稿/流程?
谢谢。
流量keys,让你说的像:
const countries = {
US: "United States",
IT: "Italy",
FR: "France"
};
type Country = $Keys<typeof countries>;
const italy: Country = 'IT';
Run Code Online (Sandbox Code Playgroud)
但如果我想有一个values的Country,我无法找到正确的方法.
我想要的东西:
function getCountryPopulation(country: $Values<typeof countries>){
...
}
getCountryPopulation(countries.US) //fine
getCountryPopulation("United States") //fine
getCountryPopulation("Canada") //fail
Run Code Online (Sandbox Code Playgroud) 我想在外部库定义中声明一个组件(我正在编写流类型react-bootstrap),以便我有可选和必需的道具,而且没有额外的道具.我有以下内容:
declare export type AlertProps = {|
bsClass: bsClass,
bsStyle: ?bsStyle,
onDismiss: ?(e: SyntheticEvent) => any,
closeLabel: ?string,
style: ?style,
|}
declare export class Alert extends React$Component {
props: AlertProps;
}
Run Code Online (Sandbox Code Playgroud)
(为了这个例子,我们假设bsStyle实际上是必需的.)但是,如果省略,流仍然会抱怨bsClass
49: props: AlertProps;
^^^^^^^^^^ property `bsClass`. Property not found in
26: ? (<Alert bsStyle="danger" style={{ textAlign: 'center' }}>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ props of React element `Alert`. See: src/components/audit/AuditAlert.jsx:26
Run Code Online (Sandbox Code Playgroud)
如果我将道具包裹起来$Shape<>,我就不能拥有所需的道具.我的解决方法如下:
declare export type AlertProps = {
// required props go here
bsClass: bsClass,
} …Run Code Online (Sandbox Code Playgroud) 我在应用程序中有两个减速器,结合了减速器(reducer.js).
import { combineReducers } from 'redux';
export const reducers = {
search: searchReducer,
table: tableReducer
};
export const reducer = combineReducer(reducers);
Run Code Online (Sandbox Code Playgroud)
此外,我还有一个代码片段,可以使用来自flow-typed redux_v3.xxjs的Store 自动解析reducers(来自此Medium帖子)的商店类型
import { reducers } from './reducer';
type Reducers = typeof reducers;
type $ExtractFunctionReturn = <V>(v: (...args: any) => V) => V;
export type State = $ObjMap<Reducers, $ExtractFunctionReturn>;
export type Store = ReduxStore<State, Actions>;
Run Code Online (Sandbox Code Playgroud)
我从流式类型的CombinedReducer得到一个错误,它找不到reducers(搜索和表).
src/types.js:65
65: export type Store = ReduxStore<State, Actions>;
^^^^^ property `search`. Property not
found in
54: declare function combineReducers<O: …Run Code Online (Sandbox Code Playgroud) 声明道具:
type IProps = {
user: ?Map<string, any> & Record<IUser>,
};
Run Code Online (Sandbox Code Playgroud)
使用解构从props分配变量:
const { user } = this.props;
const { name, surname } = user.toJS(); // <---- flow doesn't like this line
Run Code Online (Sandbox Code Playgroud)
user变量是typeof Map(immutable.js map).必须使用.toJS()将其更改为对象.但随后出现流量错误/警告:
Flow: Call of method .toJS().
Method cannot be called on any member of intersection type intersection.
Run Code Online (Sandbox Code Playgroud)
试图自己处理它,失败了.
任何帮助高度赞赏!
我正在努力将流添加到React.js应用程序.我使用flow-typed来添加几个包,这似乎是有效的.
这个问题是我使用的是Material-UI测试版.他们没有流式输入的回购,但他们确实提供了Component.js.flow文件.
但是,我收到此错误:
Error: src/NotFound/NotFound.js:6
6: import Button from 'material-ui/Button'
^^^^^^^^^^^^^^^^^^^^ material-ui/Button. Required module not found
Error: src/NotFound/NotFound.js:8
8: import { withStyles } from 'material-ui/styles'
^^^^^^^^^^^^^^^^^^^^ material-ui/styles. Required module not found
Run Code Online (Sandbox Code Playgroud)
我的.flowconfig:
[ignore]
<PROJECT_ROOT>/node_modules/.*
<PROJECT_ROOT>/build/.*
<PROJECT_ROOT>/scripts/.*
<PROJECT_ROOT>/coverage/.*
<PROJECT_ROOT>/config/.*
.*\.test\.js
[include]
[libs]
<PROJECT_ROOT>/flow-typed/.*
[lints]
[options]
emoji=true
Run Code Online (Sandbox Code Playgroud)
我在支持论坛中尝试了几种解决方案,但我仍然不了解如何连接它.
重要包装版本:
react@15.5.4
material-ui@1.0.0-beta.8
flow-bin@0.54.0
Run Code Online (Sandbox Code Playgroud) 我想确保我得到的值是一个十六进制字符串。目前我说
type Color = string;
function foo(color: Color){}
Run Code Online (Sandbox Code Playgroud)
但是我想说
type Color = '#' + stringOfLength-3-6-8;
function foo(color: Color){}
Run Code Online (Sandbox Code Playgroud)
有没有办法在流程中表达这样的约束?
flowtype ×9
javascript ×4
reactjs ×4
debugging ×1
flow-typed ×1
immutable.js ×1
node.js ×1
redux ×1
rxjs5 ×1
typescript ×1