UNPKG

parse-mobx

Version:

A wrapper for ParseJS SDK to make Parse Objects observable in Mobx

56 lines (55 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.configureParseMobx = configureParseMobx; exports.getParseInstance = getParseInstance; exports.isConfigured = isConfigured; exports.resetConfiguration = resetConfiguration; // Parse configuration module let parseInstance = null; /** * Configure the Parse instance to use with ParseMobx * @param parse - The Parse instance (from 'parse') */ function configureParseMobx(parse) { if (!parse) { throw new Error('Parse instance is required'); } // Basic validation - check for essential Parse methods if (typeof parse.Object !== 'function' || typeof parse.Query !== 'function') { throw new Error('Invalid Parse instance: missing Object or Query constructor'); } parseInstance = parse; // Make Parse available globally for backward compatibility // TODO: Remove this once all internal code is updated to use getParseInstance() if (typeof global !== 'undefined') { global.Parse = parse; } else if (typeof window !== 'undefined') { window.Parse = parse; } } /** * Get the configured Parse instance * @returns The configured Parse instance * @throws Error if Parse has not been configured */ function getParseInstance() { if (!parseInstance) { throw new Error('ParseMobx is not configured. Please call configureParseMobx(parse) first.\n' + 'Example: import Parse from "parse"; configureParseMobx(Parse);'); } return parseInstance; } /** * Check if Parse has been configured * @returns true if Parse is configured, false otherwise */ function isConfigured() { return parseInstance !== null; } /** * Reset the Parse configuration (mainly for testing) */ function resetConfiguration() { parseInstance = null; }