UNPKG

@fe6/water-pro

Version:

An enterprise-class UI design language and Vue-based implementation

49 lines (42 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createContext = createContext; exports.useContext = useContext; var _vue = require("vue"); /** @format */ function createContext(context) { var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Symbol(); var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var _options$readonly = options.readonly, readonly = _options$readonly === void 0 ? true : _options$readonly, _options$createProvid = options.createProvider, createProvider = _options$createProvid === void 0 ? false : _options$createProvid, _options$native = options.native, _native = _options$native === void 0 ? false : _options$native; var state = (0, _vue.reactive)(context); var provideData = readonly ? (0, _vue.readonly)(state) : state; !createProvider && (0, _vue.provide)(key, _native ? context : provideData); var Provider = createProvider ? (0, _vue.defineComponent)({ name: 'Provider', inheritAttrs: false, setup: function setup(_, _ref) { var slots = _ref.slots; (0, _vue.provide)(key, provideData); return function () { var _a; return (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots); }; } }) : null; return { Provider: Provider, state: state }; } function useContext() { var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Symbol(); var defaultValue = arguments.length > 1 ? arguments[1] : undefined; return (0, _vue.inject)(key, defaultValue || {}); }