當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript LocalStorage.getItem函數代碼示例

本文整理匯總了TypeScript中tinymce/core/api/util/LocalStorage.getItem函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getItem函數的具體用法?TypeScript getItem怎麽用?TypeScript getItem使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了getItem函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

 suite.test('getItem', function () {
   LocalStorage.setItem('a', '1');
   LegacyUnit.equal(LocalStorage.getItem('a'), '1');
   LocalStorage.setItem('a', '0');
   LegacyUnit.equal(LocalStorage.getItem('a'), '0');
   LegacyUnit.equal(LocalStorage.getItem('b'), null);
 });
開發者ID:abstask,項目名稱:tinymce,代碼行數:7,代碼來源:LocalStorageTest.ts

示例2:

const restoreDraft = (editor: Editor) => {
  const prefix = Settings.getAutoSavePrefix(editor);

  if (hasDraft(editor)) {
    editor.setContent(LocalStorage.getItem(prefix + 'draft'), { format: 'raw' });
    Events.fireRestoreDraft(editor);
  }
};
開發者ID:tinymce,項目名稱:tinymce,代碼行數:8,代碼來源:Storage.ts

示例3: parseInt

const hasDraft = (editor: Editor) => {
  const time = parseInt(LocalStorage.getItem(Settings.getAutoSavePrefix(editor) + 'time'), 10) || 0;

  if (new Date().getTime() - time > Settings.getAutoSaveRetention(editor)) {
    removeDraft(editor, false);
    return false;
  }

  return true;
};
開發者ID:tinymce,項目名稱:tinymce,代碼行數:10,代碼來源:Storage.ts

示例4: default

export default (max: number = 10) => {
  const storageString = LocalStorage.getItem(storageName);
  const localstorage = Type.isString(storageString) ? JSON.parse(storageString) : [];

  const prune = (list: string[]): string[] => {
    // When the localStorage cache is too big,
    // remove the difference from the tail (head is fresh, tail is stale!)
    const diff = max - list.length;
    return (diff < 0) ? list.slice(0, max) : list;
  };

  const cache = prune(localstorage);

  const add = (key: string): void => {
    // Remove duplicates first.
    Arr.indexOf(cache, key).each(remove);

    cache.unshift(key);

    // When max size is exceeded, the oldest colors will be removed
    if (cache.length > max) {
      cache.pop();
    }

    LocalStorage.setItem(storageName, JSON.stringify(cache));
  };

  const remove = (idx: number): void => {
    cache.splice(idx, 1);
  };

  const state = (): string[] => {
    return cache.slice(0);
  };

  return {
    add,
    state
  };
};
開發者ID:tinymce,項目名稱:tinymce,代碼行數:40,代碼來源:ColorCache.ts


注:本文中的tinymce/core/api/util/LocalStorage.getItem函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。