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


TypeScript data.select函數代碼示例

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


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

示例1: setFootnotes

function* setFootnotes() {
    const items = select('abt/data').getFootnotes();
    const blocksList = select<Block[]>('core/block-editor').getBlocks();
    const footnoteBlockIndex = blocksList.findIndex(
        ({ name }) => name === 'abt/footnotes',
    );
    const bibliographyBlockIndex = blocksList.findIndex(
        ({ name }) => name === 'abt/bibliography',
    );
    if (items.length > 0 && footnoteBlockIndex >= 0) {
        yield dispatch('core/block-editor').updateBlockAttributes(
            blocksList[footnoteBlockIndex].clientId,
            { items },
        );
    } else if (items.length > 0 && footnoteBlockIndex === -1) {
        yield dispatch('core/block-editor').insertBlock(
            createBlock('abt/footnotes', {
                items,
            }),
            bibliographyBlockIndex > 0
                ? bibliographyBlockIndex
                : blocksList.length,
            undefined,
            false,
        );
    } else if (items.length === 0 && footnoteBlockIndex >= 0) {
        yield dispatch('core/block-editor').removeBlock(
            blocksList[footnoteBlockIndex].clientId,
        );
    }
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:31,代碼來源:actions.ts

示例2: saveState

export function saveState() {
    const id = select('core/editor').getCurrentPostId();
    const post = select('abt/data').getSerializedState();
    return {
        type: CtrlActions.SAVE_STATE,
        id,
        state: post.meta._abt_state,
    };
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:9,代碼來源:controls.ts

示例3: getEditorDOM

export function getEditorDOM(excludeInvalid: boolean = false): HTMLDivElement {
    const doc = document.createElement('div');
    if (excludeInvalid) {
        const filteredBlocks = select<Block[]>('core/editor')
            .getBlocksForSerialization()
            .filter(
                block =>
                    !INVALID_BLOCK_TYPES.includes(block.name) && block.isValid,
            );
        doc.innerHTML = serialize(filteredBlocks);
    } else {
        doc.innerHTML = select<string>('core/editor').getEditedPostContent();
    }
    return doc;
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:15,代碼來源:editor.ts

示例4: setBibliography

function* setBibliography({ items, meta }: Processor.Bibliography) {
    const blocksList = select<Block[]>('core/block-editor').getBlocks();
    const bibliographyBlock = blocksList.find(
        block => block.name === 'abt/bibliography',
    );
    if (items.length > 0 && bibliographyBlock) {
        yield dispatch('core/block-editor').updateBlockAttributes(
            bibliographyBlock.clientId,
            { ...meta, items },
        );
    } else if (items.length > 0 && !bibliographyBlock) {
        yield dispatch('core/block-editor').insertBlock(
            createBlock('abt/bibliography', {
                ...meta,
                items,
            }),
            blocksList.length,
            undefined,
            false,
        );
    } else if (items.length === 0 && bibliographyBlock) {
        yield dispatch('core/block-editor').removeBlock(
            bibliographyBlock.clientId,
        );
    }
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:26,代碼來源:actions.ts

示例5: fetchStyle

export function fetchStyle() {
    const { value, kind } = select('abt/data').getStyle();
    if (kind === StyleKind.CUSTOM) {
        return value;
    }
    return {
        type: CtrlActions.FETCH_STYLE,
        id: value,
    };
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:10,代碼來源:controls.ts

示例6: parseCitations

export function* parseCitations() {
    const styleXml: string = yield fetchStyle();
    yield fetchLocale(styleXml);
    const processor = new Processor(styleXml);
    const citations = processor.parseCitations(
        select('abt/data').getCitationsByIndex(),
    );
    yield setBibliography(processor.bibliography);
    yield updateEditorCitations(citations);
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:10,代碼來源:actions.ts

示例7: updateReference

export function* updateReference(data: CSL.Data) {
    const itemIsCited =
        select('abt/data')
            .getCitedItems()
            .findIndex(item => item.id === data.id) >= 0;
    yield {
        type: Actions.UPDATE_REFERENCE,
        data,
    };
    if (itemIsCited) {
        yield parseCitations();
    }
    yield save();
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:14,代碼來源:actions.ts


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