本文整理匯總了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);
});
示例2:
const restoreDraft = (editor: Editor) => {
const prefix = Settings.getAutoSavePrefix(editor);
if (hasDraft(editor)) {
editor.setContent(LocalStorage.getItem(prefix + 'draft'), { format: 'raw' });
Events.fireRestoreDraft(editor);
}
};
示例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;
};
示例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
};
};