ngrx/Store和reducer都是新手.基本上,我有这个减速器:
import {StoreData, INITIAL_STORE_DATA} from "../store-data";
import {Action} from "@ngrx/store";
import {
USER_THREADS_LOADED_ACTION, UserThreadsLoadedAction, SEND_NEW_MESSAGE_ACTION,
SendNewMessageAction
} from "../actions";
import * as _ from "lodash";
import {Message} from "../../shared-vh/model/message";
import {ThreadsService} from "../../shared-vh/services/threads.service";
export function storeData(state: StoreData = INITIAL_STORE_DATA, action: Action): StoreData {
switch (action.type) {
case SEND_NEW_MESSAGE_ACTION:
return handleSendNewMessageAction(state, action);
default:
return state
}
}
function handleSendNewMessageAction(state:StoreData, action:SendNewMessageAction): StoreData {
const newStoreData = _.cloneDeep(state);
const currentThread = newStoreData.threads[action.payload.threadId];
const newMessage: Message = {
text: action.payload.text,
threadId: action.payload.threadId,
timestamp: new …
Run Code Online (Sandbox Code Playgroud) 想知道你是否可以提供一些帮助.我似乎得到自己当涉及到使用有点困惑catch
与Observable
秒.
基本上我要做的是以下内容:当我的API返回403错误时,我想对我执行一些操作TokenStore
,即删除本地令牌并将用户标记为未经身份验证.我试图这样做的方式可能是错误的,所以请告诉我是否有更好的方法来实现这一点.
我正在尝试使用以下代码完成此操作:
APIConnector.service.ts - API通信方法的单一服务
import {Injectable} from 'angular2/core';
import {Http, Response, Headers, RequestOptions} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import * as _ from 'lodash';
import {Logger} from './logger.service';
import {TokenStore} from '../stores/token.store';
@Injectable()
export class APIConnector {
private _apiUrl:string = 'https://api.sb.zerojargon.com/';
private _token:string = null;
constructor(
private _http:Http,
private _logger:Logger,
private _tokenStore:TokenStore
) {}
get(endpoint:String, includes:Array<string>) {
let includeString = (!_.isUndefined(includes)) ? this._parseIncludes(includes) : '';
let headers = this._createHeaders();
let options …
Run Code Online (Sandbox Code Playgroud) 我已经阅读了关于这个问题的几个问题和答案但是无法解决它.
我正在使用Ionic2,我有一个方法可以从Firebase Database v3中检索数据.我不明白为什么我在控制台中出现以下错误ionic serve
:
Error TS2345: Argument of type '(snap: DataSnapshot) => void' is not assignable to parameter of type '(a: DataSnapshot) => boolean'.
Type 'void' is not assignable to type 'boolean'.
Run Code Online (Sandbox Code Playgroud)
这是方法:
constructor(private http: Http) {
firebase.database().ref('users').orderByChild("id").on("value", function(snapshot){
let items = [];
snapshot.forEach(snap => {
items.push({
uid: snap.val().uid,
username: snap.val().username,
});
});
});
}
}
Run Code Online (Sandbox Code Playgroud) 我试图使用rxjs 5在TypeScript中编写Node.js服务器,但是在转换fs.readFile
为rxjs表单时遇到错误.我希望以下代码可以在TypeScript中使用
// This is a JavaScript example from the official documentation. It should
// also work at the TypeScript envrionment.
import * as fs from 'fs';
import { Observable } from 'rxjs';
let readFileAsObservable = Observable.bindNodeCallback(fs.readFile);
// This is the line that throws the error.
let result = readFileAsObservable('./roadNames.txt', 'utf8');
result.subscribe(x => console.log(x), e => console.error(e));
Run Code Online (Sandbox Code Playgroud)
但是,当我添加第二个参数时,我的编辑器会报告TypeScript错误 'utf-8'
Supplied parameters do not match any signature of call target.
Run Code Online (Sandbox Code Playgroud)
我试图找到如何使用fs.readFile()
in rxjs和TypeScript 的指南,但没有太多运气.
更新到TypeScript 2.4.1后,编译使用Actions
observable from @ngrx/effects
(版本2.0.3)的项目会看到抛出以下错误:
Error TS2684: The 'this' context of type 'Actions' is not assignable to method's 'this' of type 'Observable<any>'.
Error TS7006: Parameter 'action' implicitly has an 'any' type.
Error TS2345: Argument of type 'Actions' is not assignable to parameter of type 'Observable<Action>'.
Types of property 'lift' are incompatible.
Type '(operator: Operator<any, Action>) => Observable<Action>' is not assignable to type '<R>(operator: Operator<Action, R>) => Observable<R>'.
Types of parameters 'operator' and 'operator' are incompatible.
Type 'Operator<Action, R>' …
Run Code Online (Sandbox Code Playgroud) 当使用 chai 进行单元测试时,我不断收到此错误消息,并且没有一个测试通过,即使它们应该通过。在这种情况下这意味着什么?谢谢。
var chai = require('chai');
var chaiHttp = require('chai-http');
var server = require('../server.js');
var should = chai.should();
var app = server.app;
var storage = server.storage;
chai.use(chaiHttp);
describe('Shopping List', function() {
it('should list items on GET', function(done) {
chai.request(app)
.get('/items')
.end(function(err, res) {
res.should.have.status(200);
res.should.be.json; // jshint ignore:line
res.body.should.be.a('array');
res.body.should.have.length(3);
res.body[0].should.be.a('object');
res.body[0].should.have.property('id');
res.body[0].should.have.property('name');
res.body[0].id.should.be.a('number');
res.body[0].name.should.be.a('string');
res.body[0].name.should.equal('Broad beans');
res.body[1].name.should.equal('Tomatoes');
res.body[2].name.should.equal('Peppers');
done();
});
});
Run Code Online (Sandbox Code Playgroud)
完整错误消息:
1) Shopping List should list items on GET:
TypeError: Cannot read property 'address' of undefined
at …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的package.json中添加lint-fix。我的基本皮棉是"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
我确实尝试过,"lint-fix": "eslint --fix --ext .js,.vue src test/unit/specs test/e2e/specs"
但是它抛出了我的错误,但没有修复它们。
我必须改变什么?
NPM的错误是:
217 problems (217 errors, 0 warnings)
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run-script" "lint-fix"
npm ERR! node v5.10.1
npm ERR! npm v3.8.3
npm ERR! code ELIFECYCLE
npm ERR! quasar-app@0.0.1 lint-fix: eslint --fix --ext .js,.vue src
npm ERR! Exit status 1
npm ERR! but it is caused by exit code 1 which is result of finding …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个删除函数,它将从Firebase中删除我的对象.
我在FireBase上有以下结构:
recipes recipebooks recipesPerRecipebook
- id - id - recipebook_id
- id - id - recipe_id: true
Run Code Online (Sandbox Code Playgroud)
当我点击删除我要删除我想要做的就是recipe_id
从recipes
和也删除 recipesPerRecipebook/${recipebook_id}
我在recipes.service.ts中创建了一个函数
deleteRecipe(recipe_id:string, recipebook_id:string) {
this.sdkDb.child('recipes').remove(recipe_id)
.then(
() => alert('recipe deletion requested !')
);
this.sdkDb.child('recipesPerRecipebook/${recipebook_id}').remove(recipe_id)
.then(
() => alert('recipe Association deletion requested !')
);
}
Run Code Online (Sandbox Code Playgroud)
然后我在recipeDetails.component.ts中有这个
delete() {
this.recipesService.deleteRecipe(this.recipe.$key, this.recipe.recipebook_id);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
error_handler.js:54 Error: Firebase.remove failed: first argument must be a valid function.
我有两个问题,首先是最重要的是我哪里出错了.其次做this.sdkdb.child(...
两次感觉有点不对劲,我可以简化这个吗?
我正在尝试 browserify,我的项目目录中有以下文件
示例.js
module.exports = 'Hello, world';
Run Code Online (Sandbox Code Playgroud)索引.js
window.alert(require('./sample'));
Run Code Online (Sandbox Code Playgroud)有人可以帮助我如何使用 browserify 运行它吗?我正在使用 Windows。
我正在使用Angular 2中的Portal.在登录时,我向服务器发出请求以获取登录的用户配置文件.获取用户配置文件的方法返回一个observable,它在应用程序加载时在6个不同的位置订阅.
如果我使用了cold observable,这将导致对服务器的6个API调用.所以我通过添加.publishLast().refCount()切换到热观察.
这导致单个请求共享数据,因为用户配置文件不会在后续请求中更新.
问题从这里开始:
现在我有一个编辑配置文件功能,它通过HTTP PUT更新用户配置文件,因此,我想使先前订阅的Observables到期并以某种方式再次触发序列,以便再次执行API并且订阅接收更新的数据.
有什么方法可以重新启动/重新触发已订阅的可观察序列吗?
这是fetch用户可观察的代码
fetch(){
this.userObservable = Observable.fromPromise(this.getToken())
.switchMap(token => {
let headers = new Headers();
headers.append('Authorization', `Bearer ${token}`);
return this.http.get('/api/v1/admin/users/me?includes=role', {headers: headers})
})
.map((res: Response) => {
let retVal: any = {
data: new Deserializer({
keyForAttribute: 'camelCase'
}).deserialize(res.json())
};
this.user = retVal.data as MpUser;
this.user.role = MpRoles[retVal.data.role[0].name];
return this.user;
})
.publishLast()
.refCount();
}
Run Code Online (Sandbox Code Playgroud) angular ×4
firebase ×2
javascript ×2
ngrx ×2
rxjs ×2
rxjs5 ×2
typescript ×2
angularfire2 ×1
browserify ×1
chai ×1
closures ×1
eslint ×1
ionic2 ×1
mocha.js ×1
node.js ×1
npm ×1
npm-scripts ×1
redux ×1
scope ×1
unit-testing ×1
windows ×1