From 0d567fc8c38cb63f0162d3f72130bfd812b134bd Mon Sep 17 00:00:00 2001 From: ersimont <8042088+ersimont@users.noreply.github.com> Date: Sun, 1 Nov 2020 13:47:59 -0500 Subject: [PATCH] feat: include a copy of redux types, so its not a required dependency --- CHANGELOG.md | 3 +- TODO.md | 1 + docs/rxjs-core/index.html | 2 +- package.json | 2 - .../rxjs-core/src/lib/devtools/actions.ts | 45 +++++ .../src/lib/devtools/enhancer-options.ts | 175 ++++++++++++++++++ .../log-to-redux-devtools-extension.spec.ts | 0 .../log-to-redux-devtools-extension.ts | 2 +- projects/rxjs-core/src/lib/index.ts | 2 +- yarn.lock | 17 +- 10 files changed, 227 insertions(+), 22 deletions(-) create mode 100644 projects/rxjs-core/src/lib/devtools/actions.ts create mode 100644 projects/rxjs-core/src/lib/devtools/enhancer-options.ts rename projects/rxjs-core/src/lib/{ => devtools}/log-to-redux-devtools-extension.spec.ts (100%) rename projects/rxjs-core/src/lib/{ => devtools}/log-to-redux-devtools-extension.ts (95%) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1f276bc..edd157e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,8 @@ All notable changes to this project will be documented in this file. See [standa ### [0.0.5](https://github.com/simontonsoftware/s-libs/compare/v0.0.4...v0.0.5) (2020-11-01) - ### Bug Fixes -* change internal import paths to match how they will be used externally ([1020f8f](https://github.com/simontonsoftware/s-libs/commit/1020f8f270c0cabb4376cc001ebdb2e3430772dd)) +- change internal import paths to match how they will be used externally ([1020f8f](https://github.com/simontonsoftware/s-libs/commit/1020f8f270c0cabb4376cc001ebdb2e3430772dd)) ### 0.0.4 (2020-11-01) diff --git a/TODO.md b/TODO.md index 6653b4b6..62c7891b 100644 --- a/TODO.md +++ b/TODO.md @@ -10,3 +10,4 @@ - switch from yarn to pnpm - landing page to link to all API docs - coveralls +- bump peerDependencies in each package along with version diff --git a/docs/rxjs-core/index.html b/docs/rxjs-core/index.html index c05df837..ce5abb53 100644 --- a/docs/rxjs-core/index.html +++ b/docs/rxjs-core/index.html @@ -1145,7 +1145,7 @@

logToReduxDevtoolsExtension

  • diff --git a/package.json b/package.json index f91b026a..b6389f46 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,6 @@ "ng-packagr": "^10.0.0", "prettier": "^2.0.5", "protractor": "~7.0.0", - "redux": "^4.0.5", - "redux-devtools-extension": "^2.13.8", "sinon": "^9.0.2", "source-map-explorer": "^2.0.1", "standard-version": "^9.0.0", diff --git a/projects/rxjs-core/src/lib/devtools/actions.ts b/projects/rxjs-core/src/lib/devtools/actions.ts new file mode 100644 index 00000000..c351c1a9 --- /dev/null +++ b/projects/rxjs-core/src/lib/devtools/actions.ts @@ -0,0 +1,45 @@ +// Copied from https://github.com/reduxjs/redux/blob/b3165d0cbd0d8f48142284807d764160df26d6fa/src/types/actions.ts, to avoid requiring `redux` as an installed dependency just for this typing. + +// tslint:disable + +/** + * An *action* is a plain object that represents an intention to change the + * state. Actions are the only way to get data into the store. Any data, + * whether from UI events, network callbacks, or other sources such as + * WebSockets needs to eventually be dispatched as actions. + * + * Actions must have a `type` field that indicates the type of action being + * performed. Types can be defined as constants and imported from another + * module. It's better to use strings for `type` than Symbols because strings + * are serializable. + * + * Other than `type`, the structure of an action object is really up to you. + * If you're interested, check out Flux Standard Action for recommendations on + * how actions should be constructed. + * + * @template T the type of the action's `type` tag. + */ +export interface Action { + type: T; +} + +/** + * An *action creator* is, quite simply, a function that creates an action. Do + * not confuse the two terms—again, an action is a payload of information, and + * an action creator is a factory that creates an action. + * + * Calling an action creator only produces an action, but does not dispatch + * it. You need to call the store's `dispatch` function to actually cause the + * mutation. Sometimes we say *bound action creators* to mean functions that + * call an action creator and immediately dispatch its result to a specific + * store instance. + * + * If an action creator needs to read the current state, perform an API call, + * or cause a side effect, like a routing transition, it should return an + * async action instead of an action. + * + * @template A Returned action type. + */ +export interface ActionCreator { + (...args: P): A; +} diff --git a/projects/rxjs-core/src/lib/devtools/enhancer-options.ts b/projects/rxjs-core/src/lib/devtools/enhancer-options.ts new file mode 100644 index 00000000..c9476461 --- /dev/null +++ b/projects/rxjs-core/src/lib/devtools/enhancer-options.ts @@ -0,0 +1,175 @@ +import { Action, ActionCreator } from './actions'; + +// copied from https://github.com/zalmoxisus/redux-devtools-extension/blob/3df4d939b548b8ec891c73dabe2ffdd5dd2a8119/npm-package/index.d.ts, to avoid required `redux-devtools-extension` as an installed dependency just for this typing. + +// tslint:disable + +/** + * Copied from `redux-devtools-extension`, to avoid requiring it as an installed dependency just for this interface. + */ +export interface EnhancerOptions { + /** + * the instance name to be showed on the monitor page. Default value is `document.title`. + * If not specified and there's no document title, it will consist of `tabId` and `instanceId`. + */ + name?: string; + /** + * action creators functions to be available in the Dispatcher. + */ + actionCreators?: ActionCreator[] | { [key: string]: ActionCreator }; + /** + * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once. + * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly. + * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value). + * + * @default 500 ms. + */ + latency?: number; + /** + * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. + * + * @default 50 + */ + maxAge?: number; + /** + * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). + * - `false` - will handle also circular references. + * - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions. + * - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys. + * For each of them you can indicate if to include (by setting as `true`). + * For `function` key you can also specify a custom function which handles serialization. + * See [`jsan`](https://github.com/kolodny/jsan) for more details. + */ + serialize?: + | boolean + | { + date?: boolean; + regex?: boolean; + undefined?: boolean; + error?: boolean; + symbol?: boolean; + map?: boolean; + set?: boolean; + function?: boolean | Function; + }; + /** + * function which takes `action` object and id number as arguments, and should return `action` object back. + */ + actionSanitizer?: (action: A, id: number) => A; + /** + * function which takes `state` object and index as arguments, and should return `state` object back. + */ + stateSanitizer?: (state: S, index: number) => S; + /** + * *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). + * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. + */ + actionsBlacklist?: string | string[]; + /** + * *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). + * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. + */ + actionsWhitelist?: string | string[]; + /** + * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor. + * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters. + */ + predicate?: (state: S, action: A) => boolean; + /** + * if specified as `false`, it will not record the changes till clicking on `Start recording` button. + * Available only for Redux enhancer, for others use `autoPause`. + * + * @default true + */ + shouldRecordChanges?: boolean; + /** + * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type. + * If not specified, will commit when paused. Available only for Redux enhancer. + * + * @default "@@PAUSED"" + */ + pauseActionType?: string; + /** + * auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use. + * Not available for Redux enhancer (as it already does it but storing the data to be sent). + * + * @default false + */ + autoPause?: boolean; + /** + * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button. + * Available only for Redux enhancer. + * + * @default false + */ + shouldStartLocked?: boolean; + /** + * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer. + * + * @default true + */ + shouldHotReload?: boolean; + /** + * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched. + * + * @default false + */ + shouldCatchErrors?: boolean; + /** + * If you want to restrict the extension, specify the features you allow. + * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed. + * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side. + * Otherwise, you'll get/set the data right from the monitor part. + */ + features?: { + /** + * start/pause recording of dispatched actions + */ + pause?: boolean; + /** + * lock/unlock dispatching actions and side effects + */ + lock?: boolean; + /** + * persist states on page reloading + */ + persist?: boolean; + /** + * export history of actions in a file + */ + export?: boolean | 'custom'; + /** + * import history of actions from a file + */ + import?: boolean | 'custom'; + /** + * jump back and forth (time travelling) + */ + jump?: boolean; + /** + * skip (cancel) actions + */ + skip?: boolean; + /** + * drag and drop actions in the history list + */ + reorder?: boolean; + /** + * dispatch custom actions or action creators + */ + dispatch?: boolean; + /** + * generate tests for the selected actions + */ + test?: boolean; + }; + /** + * Set to true or a stacktrace-returning function to record call stack traces for dispatched actions. + * Defaults to false. + */ + trace?: boolean | ((action: A) => string); + /** + * The maximum number of stack trace entries to record per action. Defaults to 10. + */ + traceLimit?: number; +} diff --git a/projects/rxjs-core/src/lib/log-to-redux-devtools-extension.spec.ts b/projects/rxjs-core/src/lib/devtools/log-to-redux-devtools-extension.spec.ts similarity index 100% rename from projects/rxjs-core/src/lib/log-to-redux-devtools-extension.spec.ts rename to projects/rxjs-core/src/lib/devtools/log-to-redux-devtools-extension.spec.ts diff --git a/projects/rxjs-core/src/lib/log-to-redux-devtools-extension.ts b/projects/rxjs-core/src/lib/devtools/log-to-redux-devtools-extension.ts similarity index 95% rename from projects/rxjs-core/src/lib/log-to-redux-devtools-extension.ts rename to projects/rxjs-core/src/lib/devtools/log-to-redux-devtools-extension.ts index e03f16b3..3d92b3f8 100644 --- a/projects/rxjs-core/src/lib/log-to-redux-devtools-extension.ts +++ b/projects/rxjs-core/src/lib/devtools/log-to-redux-devtools-extension.ts @@ -1,5 +1,5 @@ -import { EnhancerOptions } from 'redux-devtools-extension'; import { Observable, Subscription } from 'rxjs'; +import { EnhancerOptions } from './enhancer-options'; /** @hidden */ export interface Connection { diff --git a/projects/rxjs-core/src/lib/index.ts b/projects/rxjs-core/src/lib/index.ts index ecfeb302..e93e1b70 100644 --- a/projects/rxjs-core/src/lib/index.ts +++ b/projects/rxjs-core/src/lib/index.ts @@ -1,4 +1,4 @@ export * from './operators'; export { createOperatorFunction } from './create-operator-function'; -export { logToReduxDevtoolsExtension } from './log-to-redux-devtools-extension'; +export { logToReduxDevtoolsExtension } from './devtools/log-to-redux-devtools-extension'; export { SubscriptionManager } from './subscription-manager'; diff --git a/yarn.lock b/yarn.lock index 1d772926..e7165d30 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6492,7 +6492,7 @@ loglevel@^1.6.8: resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.7.0.tgz#728166855a740d59d38db01cf46f042caa041bb0" integrity sha512-i2sY04nal5jDcagM3FMfG++T69GEEM8CYuOfeOIvmXzOIcwE9a/CJPR0MFM97pYMj/u10lzz7/zd7+qwhrBTqQ== -loose-envify@^1.0.0, loose-envify@^1.4.0: +loose-envify@^1.0.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== @@ -8656,19 +8656,6 @@ redent@^3.0.0: indent-string "^4.0.0" strip-indent "^3.0.0" -redux-devtools-extension@^2.13.8: - version "2.13.8" - resolved "https://registry.yarnpkg.com/redux-devtools-extension/-/redux-devtools-extension-2.13.8.tgz#37b982688626e5e4993ff87220c9bbb7cd2d96e1" - integrity sha512-8qlpooP2QqPtZHQZRhx3x3OP5skEV1py/zUdMY28WNAocbafxdG2tRD1MWE7sp8obGMNYuLWanhhQ7EQvT1FBg== - -redux@^4.0.5: - version "4.0.5" - resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f" - integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w== - dependencies: - loose-envify "^1.4.0" - symbol-observable "^1.2.0" - reflect-metadata@^0.1.2: version "0.1.13" resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08" @@ -9993,7 +9980,7 @@ svgo@^1.0.0: unquote "~1.1.1" util.promisify "~1.0.0" -symbol-observable@1.2.0, symbol-observable@^1.2.0: +symbol-observable@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==