New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bloc-react

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bloc-react - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

src/lib/BlocConsumer.test.ts

4

dist/my-lib.d.ts

@@ -28,2 +28,3 @@ import { Subscription } from 'rxjs';

readonly blocListGlobal: BlocBase<any>[];
protected _blocMapLocal: Record<string, BlocBase<any>>;
private blocObservers;

@@ -33,2 +34,4 @@ constructor(blocs: BlocBase<any>[], options?: ReactBlocOptions$1);

addBlocObserver<T extends BlocBase<any>>(blocClass: BlocClass<T>, callback: (bloc: T, state: ValueType<T>) => unknown, scope?: BlocObserverScope): void;
addLocalBloc(key: string, bloc: BlocBase<any>): void;
removeLocalBloc(key: string): void;
}

@@ -91,3 +94,2 @@

private _contextLocalProviderKey;
private _blocMapLocal;
constructor(blocs: BlocBase<any>[], options?: ReactBlocOptions);

@@ -94,0 +96,0 @@ useBloc: <T extends BlocBase<any>>(blocClass: BlocClass<T>, options?: BlocHookOptions<T>) => BlocHookData<T>;

@@ -133,2 +133,3 @@ 'use strict';

this.observer = null;
this._blocMapLocal = {};
this.blocObservers = [];

@@ -158,2 +159,13 @@ this.blocListGlobal = blocs;

}
addLocalBloc(key, bloc) {
this._blocMapLocal[key] = bloc;
bloc.subscribe((v) => this.notify(bloc, v));
}
removeLocalBloc(key) {
const bloc = this._blocMapLocal[key];
if (bloc) {
bloc.complete();
delete this._blocMapLocal[key];
}
}
}

@@ -173,3 +185,2 @@

this._contextLocalProviderKey = React__default['default'].createContext("");
this._blocMapLocal = {};
this.useBloc = (blocClass, options = {}) => {

@@ -201,9 +212,2 @@ const mergedOptions = {

)
and mame sure you add the global state provider to your app:
const { GlobalBlocProvider } = state;
...
<GlobalBlocProvider>
<App />
</GlobalBlocProvider>
`);

@@ -259,6 +263,3 @@ console.error(error2.error);

newBloc._localProviderRef = providerKey;
this._blocMapLocal[providerKey] = newBloc;
if (this.debug) {
newBloc.subscribe((v) => this.notify(newBloc, v));
}
this.addLocalBloc(providerKey, newBloc);
return newBloc;

@@ -271,4 +272,3 @@ }, []);

return () => {
bloc.complete();
delete this._blocMapLocal[providerKey];
this.removeLocalBloc(providerKey);
};

@@ -275,0 +275,0 @@ }, []);

{
"name": "bloc-react",
"version": "0.0.4",
"version": "0.0.5",
"scripts": {

@@ -16,2 +16,3 @@ "dev": "vite",

"dependencies": {
"enzyme": "^3.11.0",
"nanoid": "^3.1.22",

@@ -26,3 +27,3 @@ "rxjs": "^6.6.7"

"@material-ui/icons": "^4.11.2",
"@types/jest": "^26.0.22",
"@types/jest": "^26.0.23",
"@types/material-ui": "^0.21.8",

@@ -29,0 +30,0 @@ "@types/react": "^17.0.3",

@@ -7,3 +7,3 @@ import Bloc from "./Bloc";

onChange: jest.fn(),
onTransition: jest.fn()
onTransition: jest.fn(),
};

@@ -64,3 +64,6 @@

expect(spy.onChange).toHaveBeenCalledTimes(1);
expect(spy.onChange).toHaveBeenCalledWith({ currentState: false, nextState: true });
expect(spy.onChange).toHaveBeenCalledWith({
currentState: false,
nextState: true,
});
});

@@ -76,3 +79,3 @@

event: AuthEvent.authenticated,
nextState: true
nextState: true,
});

@@ -79,0 +82,0 @@ });

@@ -21,3 +21,5 @@ import BlocBase from "./BlocBase";

} else {
console.error(`"mapEventToState" not implemented for "${this.constructor.name}"`);
console.error(
`"mapEventToState" not implemented for "${this.constructor.name}"`
);
}

@@ -30,5 +32,5 @@ };

event,
nextState: value
nextState: value,
});
};
}
import BlocBase from "./BlocBase";
import { BlocConsumer } from "./BlocConsumer";

@@ -13,2 +14,11 @@ describe("TestBloc", () => {

});
it("should allow setting the consumer", () => {
const bloc = new TestBloc();
try {
bloc.consumer = new BlocConsumer([]);
} catch (e) {
fail(e);
}
});
});

@@ -23,5 +23,5 @@ import { BlocConsumer } from "./BlocConsumer";

currentState: this.state,
nextState: state
nextState: state,
});
};
}

@@ -9,3 +9,3 @@ import BlocBase from "./BlocBase";

type BlocObserverScope = "local" | "global" | "all";
export type BlocObserverScope = "local" | "global" | "all";
type BlocObserver = [

@@ -21,5 +21,5 @@ BlocClass<any>,

readonly blocListGlobal: BlocBase<any>[];
protected _blocMapLocal: Record<string, BlocBase<any>> = {};
private blocObservers: BlocObserver[] = [];
// private _blocMapLocal: Record<string, BlocBase<any>> = {};
// private _contextMapLocal: Record<string, React.Context<Cubit<any>>> = {}

@@ -63,2 +63,15 @@

}
public addLocalBloc(key: string, bloc: BlocBase<any>) {
this._blocMapLocal[key] = bloc;
bloc.subscribe((v: any) => this.notify(bloc, v));
}
public removeLocalBloc(key: string) {
const bloc = this._blocMapLocal[key];
if (bloc) {
bloc.complete();
delete this._blocMapLocal[key];
}
}
}

@@ -9,2 +9,1 @@ import { BlocOptions } from "./types";

};

@@ -5,3 +5,3 @@ import Cubit from "./Cubit";

const spy = {
onChange: jest.fn()
onChange: jest.fn(),
};

@@ -40,5 +40,8 @@

cubit.increment();
expect(spy.onChange).toHaveBeenCalledWith({ currentState: 0, nextState: 1 });
expect(spy.onChange).toHaveBeenCalledWith({
currentState: 0,
nextState: 1,
});
});
});
});

@@ -5,10 +5,10 @@ import * as index from "./index";

it("should export BlocReact", () => {
expect(index).toHaveProperty('BlocReact');
expect(index).toHaveProperty("BlocReact");
});
it("should export Cubit", () => {
expect(index).toHaveProperty('Cubit');
expect(index).toHaveProperty("Cubit");
});
it("should export Bloc", () => {
expect(index).toHaveProperty('Bloc');
expect(index).toHaveProperty("Bloc");
});
});

@@ -38,3 +38,6 @@ import * as rxjs from "rxjs";

beforeEach(() => {
localStorage.setItem(LOCAL_STORAGE_PREFIX + persistKey, `{"state": ${cachedValue}}`);
localStorage.setItem(
LOCAL_STORAGE_PREFIX + persistKey,
`{"state": ${cachedValue}}`
);
});

@@ -59,3 +62,6 @@

it("should not get value from localStorage if `persistData` is false", () => {
const stream = new StreamAbstraction(initialValue, { persistKey, persistData: false });
const stream = new StreamAbstraction(initialValue, {
persistKey,
persistData: false,
});
expect(stream.state).toBe(initialValue);

@@ -66,3 +72,6 @@ });

mockConsole();
localStorage.setItem(LOCAL_STORAGE_PREFIX + persistKey, `invalid json here: state": ${cachedValue}`);
localStorage.setItem(
LOCAL_STORAGE_PREFIX + persistKey,
`invalid json here: state": ${cachedValue}`
);
const stream = new StreamAbstraction(initialValue, { persistKey });

@@ -78,3 +87,3 @@ expect(stream.state).toBe(initialValue);

error: jest.fn(),
complete: jest.fn()
complete: jest.fn(),
};

@@ -104,6 +113,6 @@

describe("Persist Data Methods", function() {
describe("Persist Data Methods", function () {
beforeEach(() => {
jest.resetAllMocks();
})
});

@@ -113,7 +122,11 @@ it("should clear the data from localstorage when `clearCache` is called", () => {

stream.clearCache();
expect(localStorage.removeItem).toHaveBeenCalledWith(LOCAL_STORAGE_PREFIX + persistKey);
expect(localStorage.removeItem).toHaveBeenCalledWith(
LOCAL_STORAGE_PREFIX + persistKey
);
});
it("should not do anything if there is no `persistKey` when `clearCache` is called", () => {
const stream = new StreamAbstractionExposed(initialValue, { persistKey: '' });
const stream = new StreamAbstractionExposed(initialValue, {
persistKey: "",
});
stream.clearCache();

@@ -131,3 +144,5 @@ expect(localStorage.removeItem).toHaveBeenCalledTimes(0);

it("should not update cache when the state is updated if `persistKey` key is undefined", () => {
const stream = new StreamAbstractionExposed(initialValue, { persistKey: '' });
const stream = new StreamAbstractionExposed(initialValue, {
persistKey: "",
});
expect(localStorage.setItem).toHaveBeenCalledTimes(0);

@@ -138,2 +153,2 @@ stream.next_exposed(55);

});
});
});

@@ -46,3 +46,3 @@ import { BehaviorSubject, Subscription } from "rxjs";

this.updateCache();
}
};

@@ -65,3 +65,5 @@ protected parseFromCache = (state: string): T => {

} catch (e) {
const error = new Error(`Failed to parse JSON in localstorage for the key: "${LOCAL_STORAGE_PREFIX}${this._options.persistKey}"`);
const error = new Error(
`Failed to parse JSON in localstorage for the key: "${LOCAL_STORAGE_PREFIX}${this._options.persistKey}"`
);
console.error(error);

@@ -68,0 +70,0 @@ return error;

@@ -22,2 +22,2 @@ import BlocBase from "./BlocBase";

persistData?: boolean;
}
}

@@ -13,4 +13,4 @@ import CounterCubit from "./bloc/CounterCubit";

export const { useBloc, GlobalBlocProvider, BlocBuilder, BlocProvider } = state;
export const { useBloc, BlocBuilder, BlocProvider } = state;
export default state;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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