@mantine_store-umd

UMD of @mantine/store

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/499643/1405080/%40mantine_store-umd.js

  1. // ==UserScript==
  2. // @name @mantine_store-umd
  3. // @namespace flomk.userscripts
  4. // @version 1.0
  5. // @description UMD of @mantine/store
  6. // @author flomk
  7. // ==/UserScript==
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
  10. typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
  11. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MantineStore = {}, global.React));
  12. })(this, (function (exports, react) { 'use strict';
  13.  
  14. function createStore(initialState) {
  15. let state = initialState;
  16. let initialized = false;
  17. const listeners = /* @__PURE__ */ new Set();
  18. return {
  19. getState() {
  20. return state;
  21. },
  22. updateState(value) {
  23. state = typeof value === "function" ? value(state) : value;
  24. },
  25. setState(value) {
  26. this.updateState(value);
  27. listeners.forEach((listener) => listener(state));
  28. },
  29. initialize(value) {
  30. if (!initialized) {
  31. state = value;
  32. initialized = true;
  33. }
  34. },
  35. subscribe(callback) {
  36. listeners.add(callback);
  37. return () => listeners.delete(callback);
  38. }
  39. };
  40. }
  41. function useStore(store) {
  42. return react.useSyncExternalStore(
  43. store.subscribe,
  44. () => store.getState(),
  45. () => store.getState()
  46. );
  47. }
  48. exports.createStore = createStore;
  49. exports.useStore = useStore;
  50. }));

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址