Comparing version 2.2.1 to 2.2.2
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
## 2.2.2 - 2020-10-27 | ||
- Create store automatically if calling `resetContext`, except for the default initial context. | ||
## 2.2.1 - 2020-10-27 | ||
@@ -5,0 +8,0 @@ - Improve a few types for plugins |
@@ -1341,3 +1341,3 @@ 'use strict'; | ||
} | ||
function openContext(options) { | ||
function openContext(options, initial) { | ||
if (options === void 0) { | ||
@@ -1347,2 +1347,6 @@ options = {}; | ||
if (initial === void 0) { | ||
initial = false; | ||
} | ||
if (context) { | ||
@@ -1445,2 +1449,6 @@ console.error('[KEA] overwriting already opened context. This may lead to errors.'); | ||
if (!initial && createStore) { | ||
context.store; | ||
} | ||
return context; | ||
@@ -1455,3 +1463,3 @@ } | ||
} | ||
function resetContext(options) { | ||
function resetContext(options, initial) { | ||
if (options === void 0) { | ||
@@ -1461,2 +1469,6 @@ options = {}; | ||
if (initial === void 0) { | ||
initial = false; | ||
} | ||
if (context) { | ||
@@ -1466,3 +1478,3 @@ closeContext(); | ||
return openContext(options); | ||
return openContext(options, initial); | ||
} | ||
@@ -2102,3 +2114,3 @@ function getPluginContext(name) { | ||
var DETACH_REDUCER$1 = DETACH_REDUCER; | ||
resetContext(); | ||
resetContext({}, true); | ||
@@ -2105,0 +2117,0 @@ exports.ATTACH_REDUCER = ATTACH_REDUCER$1; |
@@ -259,5 +259,5 @@ import { AnyAction, Reducer, Middleware, compose, StoreEnhancer, Store, Action } from 'redux'; | ||
declare function getContext(): Context; | ||
declare function openContext(options?: ContextOptions): Context; | ||
declare function openContext(options?: ContextOptions, initial?: boolean): Context; | ||
declare function closeContext(): void; | ||
declare function resetContext(options?: ContextOptions): Context; | ||
declare function resetContext(options?: ContextOptions, initial?: boolean): Context; | ||
declare function getPluginContext(name: string): Record<string, any>; | ||
@@ -264,0 +264,0 @@ declare function setPluginContext(name: string, pluginContext: Record<string, any>): void; |
@@ -1337,3 +1337,3 @@ import { createSelector } from 'reselect'; | ||
} | ||
function openContext(options) { | ||
function openContext(options, initial) { | ||
if (options === void 0) { | ||
@@ -1343,2 +1343,6 @@ options = {}; | ||
if (initial === void 0) { | ||
initial = false; | ||
} | ||
if (context) { | ||
@@ -1441,2 +1445,6 @@ console.error('[KEA] overwriting already opened context. This may lead to errors.'); | ||
if (!initial && createStore) { | ||
context.store; | ||
} | ||
return context; | ||
@@ -1451,3 +1459,3 @@ } | ||
} | ||
function resetContext(options) { | ||
function resetContext(options, initial) { | ||
if (options === void 0) { | ||
@@ -1457,2 +1465,6 @@ options = {}; | ||
if (initial === void 0) { | ||
initial = false; | ||
} | ||
if (context) { | ||
@@ -1462,3 +1474,3 @@ closeContext(); | ||
return openContext(options); | ||
return openContext(options, initial); | ||
} | ||
@@ -2098,4 +2110,4 @@ function getPluginContext(name) { | ||
var DETACH_REDUCER$1 = DETACH_REDUCER; | ||
resetContext(); | ||
resetContext({}, true); | ||
export { ATTACH_REDUCER$1 as ATTACH_REDUCER, DETACH_REDUCER$1 as DETACH_REDUCER, activatePlugin, addConnection, closeContext, connect, createAction, getContext, getPluginContext, getStore, isBreakpoint, kea, keaReducer, openContext, resetContext, setPluginContext, useActions, useAllValues, useKea, useMountedLogic, useValues }; |
@@ -5,5 +5,5 @@ import { Context, ContextOptions } from '../types'; | ||
export declare function setContext(newContext: Context): void; | ||
export declare function openContext(options?: ContextOptions): Context; | ||
export declare function openContext(options?: ContextOptions, initial?: boolean): Context; | ||
export declare function closeContext(): void; | ||
export declare function resetContext(options?: ContextOptions): Context; | ||
export declare function resetContext(options?: ContextOptions, initial?: boolean): Context; | ||
export declare function withContext(code: (context?: Context) => any, options?: {}): { | ||
@@ -10,0 +10,0 @@ context: Context; |
{ | ||
"name": "kea", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Smart front-end architecture", | ||
@@ -5,0 +5,0 @@ "author": "Marius Andra", |
@@ -20,3 +20,3 @@ import { corePlugin } from '../core' | ||
export function openContext(options: ContextOptions = {}): Context { | ||
export function openContext(options: ContextOptions = {}, initial = false): Context { | ||
if (context) { | ||
@@ -82,2 +82,3 @@ console.error('[KEA] overwriting already opened context. This may lead to errors.') | ||
// defer creating a store on the default resetContext() until it's requested | ||
Object.defineProperty(newContext, 'store', { | ||
@@ -112,2 +113,6 @@ get: function get() { | ||
if (!initial && createStore) { | ||
context.store // trigger the getter that creates the store | ||
} | ||
return context | ||
@@ -124,3 +129,3 @@ } | ||
export function resetContext(options: ContextOptions = {}): Context { | ||
export function resetContext(options: ContextOptions = {}, initial = false): Context { | ||
if (context) { | ||
@@ -130,3 +135,3 @@ closeContext() | ||
return openContext(options) | ||
return openContext(options, initial) | ||
} | ||
@@ -143,3 +148,3 @@ | ||
openContext(options) | ||
openContext(options, false) | ||
const newContext = context | ||
@@ -146,0 +151,0 @@ const returnValue = code(context) |
@@ -23,2 +23,2 @@ export * from './types' | ||
// this will create a default context | ||
resetContext() | ||
resetContext({}, true) |
274095
6895