Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-app-modules

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-app-modules - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

6

dist/app-context.js

@@ -1,2 +0,4 @@

import { createContext } from 'react';
export var AppContext = createContext(null);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
exports.AppContext = react_1.createContext(null);

@@ -1,4 +0,6 @@

import { ReplaySubject } from 'rxjs';
export var createContainer = function (providers) {
var modules$ = new ReplaySubject();
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
exports.createContainer = function (providers) {
var modules$ = new rxjs_1.ReplaySubject();
var symbols = Object.getOwnPropertySymbols(providers);

@@ -5,0 +7,0 @@ symbols.forEach(function (symbol) {

@@ -0,1 +1,2 @@

"use strict";
var __assign = (this && this.__assign) || function () {

@@ -12,6 +13,7 @@ __assign = Object.assign || function(t) {

};
import { BehaviorSubject } from 'rxjs';
import { filter, map, switchMap } from 'rxjs/operators';
export var createProvider = function (symbol, dependencySymbols, implementation) { return function (modules$) {
var resolvedDependencies$ = new BehaviorSubject({});
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
exports.createProvider = function (symbol, dependencySymbols, implementation) { return function (modules$) {
var resolvedDependencies$ = new rxjs_1.BehaviorSubject({});
var areDependenciesResolved = function () {

@@ -24,3 +26,3 @@ return dependencySymbols.every(function (d) { return resolvedDependencies$.value[d]; });

modules$
.pipe(filter(function (_a) {
.pipe(operators_1.filter(function (_a) {
var resolvedSymbol = _a.resolvedSymbol;

@@ -35,3 +37,3 @@ return resolvedSymbol !== symbol;

});
return resolvedDependencies$.pipe(filter(function () { return areDependenciesResolved(); }), switchMap(function (dependencies) { return implementation(dependencies); }), map(function (resolvedModule) { return ({
return resolvedDependencies$.pipe(operators_1.filter(function () { return areDependenciesResolved(); }), operators_1.switchMap(function (dependencies) { return implementation(dependencies); }), operators_1.map(function (resolvedModule) { return ({
resolvedSymbol: symbol,

@@ -38,0 +40,0 @@ resolvedModule: resolvedModule,

@@ -1,4 +0,10 @@

export { AppContext } from './app-context';
export { createContainer } from './create-container';
export { createProvider } from './create-provider';
export { useModule } from './use-module';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var app_context_1 = require("./app-context");
exports.AppContext = app_context_1.AppContext;
var create_container_1 = require("./create-container");
exports.createContainer = create_container_1.createContainer;
var create_provider_1 = require("./create-provider");
exports.createProvider = create_provider_1.createProvider;
var use_module_1 = require("./use-module");
exports.useModule = use_module_1.useModule;

@@ -0,4 +1,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* INTERNAL TYPES */
export var ModuleA = Symbol('ModuleA');
export var ModuleB = Symbol('ModuleB');
export var ModuleC = Symbol('ModuleC');
exports.ModuleA = Symbol('ModuleA');
exports.ModuleB = Symbol('ModuleB');
exports.ModuleC = Symbol('ModuleC');

@@ -1,10 +0,12 @@

import { useContext, useEffect, useState } from 'react';
import { AppContext } from './app-context';
export var useModule = function (symbol) {
var _a = useState(null), result = _a[0], setResult = _a[1];
var container = useContext(AppContext);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
var app_context_1 = require("./app-context");
exports.useModule = function (symbol) {
var _a = react_1.useState(null), result = _a[0], setResult = _a[1];
var container = react_1.useContext(app_context_1.AppContext);
if (container === null) {
throw Error('No provider for AppContext');
}
useEffect(function () {
react_1.useEffect(function () {
var subscription = container.modules$.subscribe(function (_a) {

@@ -11,0 +13,0 @@ var resolvedSymbol = _a.resolvedSymbol, resolvedModule = _a.resolvedModule;

{
"name": "react-app-modules",
"version": "1.0.3",
"version": "1.0.4",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

@@ -132,2 +132,7 @@ # react-app-modules

**If the following error displays in VSCode, don't panic! The error will
go away as soon as you import from `react-app-modules` in any other file.**
![Invalid Module Name](https://raw.githubusercontent.com/rrogowski/react-app-modules/HEAD/media/tutorial/invalid-module-name.png)
### Defining a Provider

@@ -262,4 +267,2 @@

**Description**
Provides module implementations to your components at

@@ -269,7 +272,7 @@ runtime without having to pass props around. For more information,

**Props**
*Props*
- `value`: a container created via `createContainer`
**Example Usage**
*Example*

@@ -295,4 +298,2 @@ ```typescript

**Description**
Maps a set of module symbols to their respective providers.

@@ -302,3 +303,3 @@ The result is passed to the `AppContext.Provider` component

**Params**
*Params*

@@ -308,3 +309,3 @@ - `providers`: an object whose keys are the set of all defined module symbols

**Example Usage**
*Example*

@@ -326,4 +327,2 @@ ```typescript

**Description**
Defines an implementation associated with a module symbol. Modules

@@ -333,3 +332,3 @@ may have dependencies on other modules, but circular dependencies are

**Params**
*Params*

@@ -347,3 +346,3 @@ - `symbol`: the module symbol that we are defining an implementation for

**Example Usage**
*Example*

@@ -365,3 +364,3 @@ ```typescript

logger.log('doing something...');
return Promise.resolve();
return Promise.resolve();
},

@@ -373,4 +372,2 @@ }));

**Description**
React hook that returns an object implementing the interface defined

@@ -380,7 +377,7 @@ for the provided module symbol. Returns `null` if the module has not

**Params**
*Params*
- `symbol`: the module symbol we want to use in this component
**Example Usage**
*Example*

@@ -387,0 +384,0 @@ ```typescript

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc