@mantine_store-umd

UMD of @mantine/store

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greasyfork.org/scripts/499643/1405080/%40mantine_store-umd.js

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name          @mantine_store-umd
// @namespace     flomk.userscripts
// @version       1.0
// @description   UMD of @mantine/store
// @author        flomk
// ==/UserScript==
(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
    typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MantineStore = {}, global.React));
})(this, (function (exports, react) { 'use strict';

    function createStore(initialState) {
        let state = initialState;
        let initialized = false;
        const listeners = /* @__PURE__ */ new Set();
        return {
            getState() {
                return state;
            },
            updateState(value) {
                state = typeof value === "function" ? value(state) : value;
            },
            setState(value) {
                this.updateState(value);
                listeners.forEach((listener) => listener(state));
            },
            initialize(value) {
                if (!initialized) {
                    state = value;
                    initialized = true;
                }
            },
            subscribe(callback) {
                listeners.add(callback);
                return () => listeners.delete(callback);
            }
        };
    }
    function useStore(store) {
        return react.useSyncExternalStore(
            store.subscribe,
            () => store.getState(),
            () => store.getState()
        );
    }
    exports.createStore = createStore;
    exports.useStore = useStore;
}));