lodash#entries TypeScript Examples

The following examples show how to use lodash#entries. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: dict.monad.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
/**
     * Returns a Dict representing the passed value as a Map.
     *
     * ```ts
     * const empty = Dict.of([]);
     * empty.get() // Map<never, never>
     *
     * const arr = Dict.of([['foo', 'bar']);
     * arr.get() // Map<string, string>
     *
     * const list = Dict.of(List.of([['foo', 'bar']));
     * list.get() // Map<string, string>
     * ```
     */
    static of<D>(val: D): Dict<D> {
        // @ts-ignore
        const sane = isIterable(val) ? val : entries(val);

        // @ts-ignore
        return new Dict<D>(new Map(sane));
    }
Example #2
Source File: dict.monad.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
/**
     * Converts Dict to List
     * ```ts
     * const fooBar = Dict.from({foo: true, bar: 1});
     * fooBar.toList().toArray() // [["foo", true], ["bar", 1]]
     * ```
     */
    toList(): List<[K, V]> {
        return List.from<[K, V]>(this.ourOriginal.entries());
    }
Example #3
Source File: roam-panel.ts    From roam-toolkit with MIT License 5 votes vote down vote up
RoamPanel = {
    /**
     * To know which sidebars were opened/closed, we track previously opened sidebar pages,
     * and diff the pages anytime something changes. Kinda like an inverse virtual dom.
     */
    onPanelChange(handleChange: (event: PanelChange) => void): DisconnectFn {
        previousIdToCount = {}

        const emitEventsForPanelDiff = (isInitialAdd: boolean = false) => {
            const idDiffEntries = entries(getPanelCountDiff())

            handleChange({
                isInitialAdd,
                addedPanels: idDiffEntries
                    .filter(([_, diff]) => diff > 0)
                    .map(([id]) => ({
                        // It's impossible to link to "Daily Notes"
                        from: id === 'DAILY_NOTES' ? null : justClickedPanelId(),
                        to: id,
                    })),
                removedPanels: idDiffEntries.filter(([_, diff]) => diff < 0).map(([id]) => id),
            })
        }

        const emitRenameEvent = async (newTitle: string) => {
            const oldId = assumeExists(justClickedPanelId())
            const justRenamedPanel = assumeExists(RoamPanel.getPanel(oldId))
            justRenamedPanel.id = namespaceId(newTitle)
            // Only emit the event after sidebar pages finish updating their titles
            await delay(10)
            // Update panel counts, in case complex sidebar pages changed their names
            previousIdToCount = tagAndCountPanels()
            handleChange({
                isInitialAdd: false,
                renamedPanel: {
                    before: oldId,
                    after: newTitle,
                },
            })
        }

        emitEventsForPanelDiff(true)
        const disconnectFns = [
            rememberLastInteractedPanel(),
            RoamEvent.onSidebarToggle(() => emitEventsForPanelDiff()),
            RoamEvent.onSidebarChange(() => emitEventsForPanelDiff()),
            RoamEvent.onChangePage(() => emitEventsForPanelDiff()),
            RoamEvent.onRenamePage(emitRenameEvent),
        ]
        return () => disconnectFns.forEach(disconnect => disconnect())
    },

    getPanel(nodeId: PanelId): PanelElement | null {
        return document.getElementById(namespaceId(nodeId))
    },

    /**
     * Tag the main panel's parent with css, so panel elements can consistently be accessed using the same selector.
     * Also allows us to apply common styles in spatial graph mode.
     */
    tagPanels() {
        // Remove panels tags that may be lingering when switching graph mode on/off
        toggleCssClassForAll(GRAPH_MODE_SCROLL_PANELS, PANEL_CSS_CLASS, !!GraphVisualization.instance)
        toggleCssClassForAll(DEFAULT_SCROLL_PANELS, PANEL_CSS_CLASS, !GraphVisualization.instance)
    },
}