Skip to content

Commit

Permalink
👽 Fix compilation errors due to typescript update
Browse files Browse the repository at this point in the history
  • Loading branch information
ryota-ka committed Oct 17, 2017
1 parent 6232edc commit 703eeeb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
13 changes: 8 additions & 5 deletions src/event-source.ts
Expand Up @@ -3,14 +3,17 @@ import {Status, PartialStatus} from './state/status';
import {empty} from 'rxjs/observable/empty';
import {of} from 'rxjs/observable/of';
import {IncomingMessage} from './state/message';
import {Channel} from './state/channel';
import {InstantMessage} from './state/ims';
import {Channel, isChannel} from './state/channel';
import {InstantMessage, isInstantMessage} from './state/ims';
import {findOne} from './util/map'
type O<T> = Observable<T>;
type BothPS = PartialStatus<IncomingMessage<Channel> | IncomingMessage<InstantMessage>>;
type ChanPS = PartialStatus<IncomingMessage<Channel>>;
type IMPS = PartialStatus<IncomingMessage<InstantMessage>>;

export class EventSource {

private _message$: O<PartialStatus<IncomingMessage<Channel> | IncomingMessage<InstantMessage>>>;
private _message$: O<BothPS>;

constructor(_status$: Observable<Status>) {
const [, message$] = _status$.partition(status => typeof status.event === 'string');
Expand All @@ -19,7 +22,7 @@ export class EventSource {
}

selectByChannelName(name: string): Observable<IncomingMessage<Channel>> {
return this._message$.mergeMap(({event, channels}) => {
return this._message$.filter<BothPS, ChanPS>((ps: BothPS): ps is ChanPS => isChannel(ps.event.channel)).mergeMap(({event, channels}) => {
const channel = findOne(channel => name === channel.name, channels);
if (channel && !event.user.is_bot) {
return of(event);
Expand All @@ -30,7 +33,7 @@ export class EventSource {
}

selectByUserName(name: string): Observable<IncomingMessage<InstantMessage>> {
return this._message$.mergeMap(({users, event, ims}) => {
return this._message$.filter<BothPS, IMPS>((ps: BothPS): ps is IMPS => isInstantMessage(ps.event.channel)).mergeMap(({users, event, ims}) => {
const user = findOne(user => name === user.name, users);
if (!user) {
return empty();
Expand Down
20 changes: 11 additions & 9 deletions src/state/channel.ts
@@ -1,4 +1,4 @@
import {where, is, pick, assoc} from 'ramda';
import {pick, assoc} from 'ramda';

export type Channel = {
id: string;
Expand All @@ -9,14 +9,16 @@ export type Channel = {
creator: string;
}

export const isChannel = where({
id: is(String),
name: is(String),
is_member: is(Boolean),
is_archived: is(Boolean),
created: is(Number),
creator: is(String)
});
export function isChannel(x: any): x is Channel {
return typeof x === 'object' &&
x !== null &&
typeof x.id === 'string' &&
typeof x.name === 'string' &&
typeof x.is_member === 'boolean' &&
typeof x.is_archived === 'boolean' &&
typeof x.created === 'number' &&
typeof x.creator === 'string';
};

const channelKeyList: Array<keyof Channel> = [
'id',
Expand Down
16 changes: 9 additions & 7 deletions src/state/ims.ts
@@ -1,4 +1,4 @@
import {where, is, pick} from 'ramda';
import {pick} from 'ramda';

export type InstantMessage = {
id: string;
Expand All @@ -7,12 +7,14 @@ export type InstantMessage = {
created: number;
}

export const isInstantMessage = where({
id: is(String),
user: is(String),
is_open: is(Boolean),
created: is(Number)
});
export function isInstantMessage(x: any): x is InstantMessage {
return typeof x === 'object' &&
x !== null &&
typeof x.id === 'string' &&
typeof x.user === 'string' &&
typeof x.is_open === 'boolean' &&
typeof x.created === 'number';
};

const imKeyList: Array<keyof InstantMessage> = [
'id',
Expand Down
2 changes: 1 addition & 1 deletion src/state/status.ts
Expand Up @@ -53,7 +53,7 @@ export function updateChannel(key: string, project: (x: Channel) => Channel): Ac
}

export function deleteChannel(key: string): Action {
return curryDel(key);
return over(lensProp('channels'), curryDel(key));
}

export function updateUser(key: string, project: (x: User) => User): Action {
Expand Down

0 comments on commit 703eeeb

Please sign in to comment.