所以,我已经看过其他关于类似问题的其他帖子,但没有一个解决方案有帮助.
我也在IntelliJ IDEA 15中进行此开发,而不是Visual Studio.我目前使用的是Typescript 2.0.3.
import { Injectable } from '@angular/core';
import { Effect, StateUpdates, toPayload } from '@ngrx/effects';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/observable/dom/webSocket'
import 'rxjs/add/operator/map';
import { AppState } from '../reducers';
import { NGRXWebSocketService } from '../shared/ngrxWebsocket.service';
import { BASE_URL } from "../shared/ngrxWebsocket.service";
export interface WebsocketMessage {
data: string
}
@Injectable()
export class WebsocketEffects {
constructor(private updates$:StateUpdates<AppState>,
private ngrxWebSocketService: NGRXWebSocketService) {
}
@Effect() _recieve$ = this.ngrxWebSocketService.getSubject()
.map((websocketUpdate: WebsocketMessage) => {
let message = JSON.parse(websocketUpdate.data);
return{ type: message.action, payload: message.payload}
});
}
Run Code Online (Sandbox Code Playgroud)
编辑1:
这是NGRXWebsocketService.
import {Injectable} from '@angular/core';
import {$WebSocket, WebSocketConfig} from 'angular2-websocket/angular2-websocket'
export const BASE_URL = 'ws://' + location.hostname + ':9000/socket';
@Injectable()
export class NGRXWebSocketService {
private socket: $WebSocket;
constructor() {
this.socket = new $WebSocket(BASE_URL);
}
public sendRequest(request) {
return this.socket.send(request);
}
public reconnect() {
this.socket = new $WebSocket(BASE_URL);
}
public getSubject() {
return this.socket.getDataStream();
}
}
Run Code Online (Sandbox Code Playgroud)
这看起来像是手动编译期间的打字问题。
在 IDE 中编译时,IDE 可能具有内部类型配置,这在您的项目设置中不存在。
npm install typings -g
检查您的package.json dependencies.
如果您有es6-shimin dependencies,请typings.json在您的项目目录中创建:
{
"globalDependencies": {
"es6-shim": "registry:dt/es6-shim",
"node": "registry:dt/node"
}
}
Run Code Online (Sandbox Code Playgroud)
如果您有core-jsin dependencies,请typings.json在您的项目目录中创建:
{
"globalDependencies": {
"core-js": "registry:dt/core-js",
"node": "registry:dt/node"
}
}
Run Code Online (Sandbox Code Playgroud)typings install
尝试手动编译。
| 归档时间: |
|
| 查看次数: |
3915 次 |
| 最近记录: |