Follow as a clean architecture
This commit is contained in:
parent
5b7f7f5dbd
commit
e0c4182f14
11 changed files with 493 additions and 10 deletions
35
src/content/repositories/FollowKeyRepository.ts
Normal file
35
src/content/repositories/FollowKeyRepository.ts
Normal 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 = [];
|
||||
}
|
||||
}
|
59
src/content/repositories/FollowMasterRepository.ts
Normal file
59
src/content/repositories/FollowMasterRepository.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
|
31
src/content/repositories/FollowSlaveRepository.ts
Normal file
31
src/content/repositories/FollowSlaveRepository.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in a new issue