message: refactor: to new message channels
diff: */
  import { message } from '@/_helpers/browser-api'
  -import { SelectionInfo } from '@/_helpers/selection'
  -import {
  - MsgType,
  - MsgIsInNotebook,
  - MsgSaveWord,
  - MsgDeleteWords,
  - MsgGetWordsByText,
  - MsgGetWords,
  - MsgGetWordsResponse,
  -} from '@/typings/message'
  export interface Word {
  /** primary key, milliseconds elapsed since the UNIX epoch */
  @@ -33,7 +23,7 @@ export interface Word {
  note: string
  }
  -export type Area = 'notebook' | 'history'
  +export type DBArea = 'notebook' | 'history'
  export function newWord(word?: Partial<Word>): Word {
  return word
  @@ -45,7 +35,7 @@ export function newWord (word?: Partial<Word>): Word {
  url: word.url || '',
  favicon: word.favicon || '',
  trans: word.trans || '',
  - note: word.note || '',
  + note: word.note || ''
  }
  : {
  date: Date.now(),
  @@ -55,43 +45,55 @@ export function newWord (word?: Partial<Word>): Word {
  url: '',
  favicon: '',
  trans: '',
  - note: '',
  + note: ''
  }
  }
  -export function isInNotebook (info: SelectionInfo): Promise<boolean> {
  - return message.send<MsgIsInNotebook>({ type: MsgType.IsInNotebook, info })
  +export function isInNotebook(word: Word): Promise<boolean> {
  + return message
  + .send({ type: 'IS_IN_NOTEBOOK', payload: word })
  .catch(logError(false))
  }
  -export async function saveWord (area: Area, info: SelectionInfo): Promise<void> {
  - await message.send<MsgSaveWord>({ type: MsgType.SaveWord, area, info })
  +export async function saveWord(area: DBArea, word: Word): Promise<void> {
  + await message.send({ type: 'SAVE_WORD', payload: { area, word } })
  }
  -export async function deleteWords (area: Area, dates?: number[]): Promise<void> {
  - await message.send({ type: MsgType.SyncServiceDownload })
  - await message.send<MsgDeleteWords>({ type: MsgType.DeleteWords, area, dates })
  +export async function deleteWords(
  + area: DBArea,
  + dates?: number[]
  +): Promise<void> {
  + await message.send({ type: 'SYNC_SERVICE_DOWNLOAD' })
  + await message.send({ type: 'DELETE_WORDS', payload: { area, dates } })
  }
  -export function getWordsByText (area: Area, text: string): Promise<Word[]> {
  - return message.send<MsgGetWordsByText>({ type: MsgType.GetWordsByText, area, text })
  +export function getWordsByText(area: DBArea, text: string): Promise<Word[]> {
  + return message.send({
  + type: 'GET_WORDS_BY_TEXT',
  + payload: {
  + area,
  + text
  + }
  + })
  }
  export function getWords(
  - area: Area,
  + area: DBArea,
  config: {
  - itemsPerPage?: number,
  - pageNum?: number,
  - filters: { [field: string]: string[] | undefined },
  - sortField?: string,
  - sortOrder?: 'ascend' | 'descend' | false,
  - searchText?: string,
  + itemsPerPage?: number
  + pageNum?: number
  + filters: { [field: string]: string[] | undefined }
  + sortField?: string
  + sortOrder?: 'ascend' | 'descend' | false
  + searchText?: string
  }
  -): Promise<MsgGetWordsResponse> {
  - return message.send<MsgGetWords, MsgGetWordsResponse>({
  - type: MsgType.GetWords,
  +) {
  + return message.send({
  + type: 'GET_WORDS',
  + payload: {
  area,
  - ...config,
  + ...config
  + }
  })
  }
  