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

deep-storage

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-storage - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

src/__tests__/async.test.ts

2

package.json
{
"name": "deep-storage",
"version": "1.0.9",
"version": "1.0.10",
"description": "Simple observable state management for reactive applications",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -41,3 +41,3 @@ Deep Storage provides observable state for reactive applications in JavaScript.

import {deep} from 'deep-storage-react';
import {connect} from 'deep-storage-react';

@@ -57,3 +57,3 @@ class TimerView extends React.Component {

const DeepTimerView = deep({timer: storage.deep('timer')})(TimerView);
const DeepTimerView = connect({timer: storage.deep('timer')})(TimerView);

@@ -60,0 +60,0 @@ ReactDOM.render((

@@ -10,3 +10,3 @@ import { DeepStorage, UsesDeepStorage } from "./index";

export interface DeepAsyncData<Request, Response> {
export interface DeepAsyncState<Request, Response> {
status: AsyncStatus;

@@ -24,7 +24,7 @@ completed: boolean;

export interface DeepAsync<Request, Response> extends
DeepAsyncData<Request, Response>,
UsesDeepStorage<DeepAsyncData<Request, Response>> {
run(request: Request): Promise<DeepAsyncData<Request, Response>>;
rerun(): Promise<DeepAsyncData<Request, Response>>;
update(response: Response): Promise<DeepAsyncData<Request, Response>>;
DeepAsyncState<Request, Response>,
UsesDeepStorage<DeepAsyncState<Request, Response>> {
run(request: Request): Promise<DeepAsyncState<Request, Response>>;
rerun(): Promise<DeepAsyncState<Request, Response>>;
updateResponse(updater: (prevState: Response) => Response): Promise<DeepAsyncState<Request, Response>>;
}

@@ -37,7 +37,7 @@

constructor(
public storage: DeepStorage<DeepAsyncData<Request, Response>>,
public storage: DeepStorage<DeepAsyncState<Request, Response>>,
public process: (request: Request) => Promise<Response>
) {
}
run = async (request: Request): Promise<DeepAsyncData<Request, Response>> => {
run = async (request: Request): Promise<DeepAsyncState<Request, Response>> => {
// todo: probably want to queue this

@@ -55,7 +55,7 @@ if (this.status === AsyncStatus.Running) throw new AlreadyRunningError();

}
rerun = (): Promise<DeepAsyncData<Request, Response>> => {
rerun = (): Promise<DeepAsyncState<Request, Response>> => {
return this.run(this.request);
}
update = async (response: Response): Promise<DeepAsyncData<Request, Response>> => {
await this.storage.update(state => ({ ...state, status: AsyncStatus.Succeeded, response, error: undefined }));
updateResponse = async (updater: (prevState: Response) => Response): Promise<DeepAsyncState<Request, Response>> => {
await this.storage.update((state: DeepAsyncState<Request, Response>) => ({ ...state, status: AsyncStatus.Succeeded, updater(state.response), error: undefined }));
return this.storage.state;

@@ -74,6 +74,10 @@ }

export const deepAsync = <Request, Response>(
storage: DeepStorage<DeepAsyncData<Request, Response>>,
export const deepAsync = async <Request, Response>(
storage: DeepStorage<DeepAsyncState<Request, Response>>,
process: (request: Request) => Promise<Response>
) => {
await storage.set({
status: AsyncStatus.Created,
});
return new DefaultDeepAsync(storage, process);

@@ -80,0 +84,0 @@ }

@@ -22,2 +22,8 @@ export * from './async';

/**
* sets a value in deep storage and notifies subscribers. shortcut for
* update where the old value is ignored
*/
set: (newValue: State) => Promise<State>;
/**
* Updates the whole state and notifies subscribers

@@ -125,2 +131,5 @@ */

}
set = (newValue: State) => {
return this.updateIn()(() => newValue);
}
setIn = (...path: Path) => <DeepState>(newValue: DeepState) => {

@@ -213,7 +222,7 @@ return this.updateIn(...path)(() => newValue);

get props() {
const result = {} as {[P in keyof State]: DeepStorage<State[P]>};
const result: any = {};
for (let key of Object.keys(this.state)) {
result[key] = this.deep(key);
}
return result;
return result as {[P in keyof State]: DeepStorage<State[P]>};
}

@@ -231,2 +240,6 @@ }

set = (newValue: State): Promise<State> => {
return this.rootStorage.setIn(...this.path)(newValue);
}
update = (callback: (s: State) => State): Promise<State> => {

@@ -271,7 +284,7 @@ return this.rootStorage.updateIn(...this.path)(callback);

get props() {
const result = {} as {[P in keyof State]: DeepStorage<State[P]>};
const result: any = {};
for (let key of Object.keys(this.state)) {
result[key] = this.deep(key);
}
return result;
return result as {[P in keyof State]: DeepStorage<State[P]>};
}

@@ -278,0 +291,0 @@ }

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