Follow as a clean architecture

This commit is contained in:
Shin'ya Ueoka 2019-05-19 09:26:52 +09:00
parent 5b7f7f5dbd
commit e0c4182f14
11 changed files with 493 additions and 10 deletions

View file

@ -0,0 +1,35 @@
export default interface FollowKeyRepository {
getKeys(): string[];
pushKey(key: string): void;
popKey(): void;
clearKeys(): void;
// eslint-disable-next-line semi
}
const current: {
keys: string[];
} = {
keys: [],
};
export class FollowKeyRepositoryImpl implements FollowKeyRepository {
getKeys(): string[] {
return current.keys;
}
pushKey(key: string): void {
current.keys.push(key);
}
popKey(): void {
current.keys.pop();
}
clearKeys(): void {
current.keys = [];
}
}

View file

@ -0,0 +1,59 @@
export default interface FollowMasterRepository {
setCurrentFollowMode(newTab: boolean, background: boolean): void;
getTags(): string[];
getTagsByPrefix(prefix: string): string[];
addTag(tag: string): void;
clearTags(): void;
getCurrentNewTabMode(): boolean;
getCurrentBackgroundMode(): boolean;
// eslint-disable-next-line semi
}
const current: {
newTab: boolean;
background: boolean;
tags: string[];
} = {
newTab: false,
background: false,
tags: [],
};
export class FollowMasterRepositoryImpl implements FollowMasterRepository {
setCurrentFollowMode(newTab: boolean, background: boolean): void {
current.newTab = newTab;
current.background = background;
}
getTags(): string[] {
return current.tags;
}
getTagsByPrefix(prefix: string): string[] {
return current.tags.filter(t => t.startsWith(prefix));
}
addTag(tag: string): void {
current.tags.push(tag);
}
clearTags(): void {
current.tags = [];
}
getCurrentNewTabMode(): boolean {
return current.newTab;
}
getCurrentBackgroundMode(): boolean {
return current.background;
}
}

View file

@ -0,0 +1,31 @@
export default interface FollowSlaveRepository {
enableFollowMode(): void;
disableFollowMode(): void;
isFollowMode(): boolean;
// eslint-disable-next-line semi
}
const current: {
enabled: boolean;
} = {
enabled: false,
};
export class FollowSlaveRepositoryImpl implements FollowSlaveRepository {
enableFollowMode(): void {
current.enabled = true;
}
disableFollowMode(): void {
current.enabled = false;
}
isFollowMode(): boolean {
return current.enabled;
}
}