Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular Signal Store #195

Merged
merged 110 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
fb319fb
feat(signal-store): create publishable library
mini-rx May 6, 2023
6b6c068
feat(signal-store): signal store
mini-rx May 6, 2023
d1c8091
feat(signal-store-angular-demo): signal-store-angular-demo
mini-rx May 6, 2023
a9f8f0f
feat(signal-store): signal store
mini-rx May 11, 2023
68271b2
feat(signal-store): signal store: Signal Selector specs
mini-rx Jun 8, 2023
b275e15
feat(signal-store): signal store: specs
mini-rx Jun 19, 2023
80cda3e
feat(signal-store): signal store: specs
mini-rx Jun 21, 2023
637c18b
feat(signal-store): signal store: specs
mini-rx Jun 23, 2023
9020ede
feat(signal-store): signal store: specs
mini-rx Jun 23, 2023
302b59f
feat(signal-store): signal store: specs
mini-rx Jun 26, 2023
7255cc4
feat(signal-store): signal store: specs
mini-rx Jun 26, 2023
821a2d0
feat(signal-store): signal store: specs
mini-rx Jun 27, 2023
0b5cb7a
npx nx migrate --run-migrations
mini-rx Jun 27, 2023
1d7a142
feat(signal-store): signal store: specs
mini-rx Jun 27, 2023
a8fb620
feat(signal-store): signal store: specs
mini-rx Jun 27, 2023
fd83ca2
feat(signal-store): signal store: specs
mini-rx Jun 29, 2023
f4c4cb7
Add npm task
spierala Jul 1, 2023
fe6d943
Fix signal store demo
spierala Jul 3, 2023
6770902
feat(signal-store): fix demo
mini-rx Jul 3, 2023
5cccc1e
feat(signal-store): fix demo
mini-rx Jul 3, 2023
3eda308
Merge branch 'signal-store-tests' of github.com:spierala/mini-rx-stor…
mini-rx Jul 3, 2023
54cfc99
feat(signal-store): signal store: specs
mini-rx Jul 3, 2023
61dd5c7
Merge pull request #191 from spierala/signal-store-tests
spierala Jul 3, 2023
3655bd5
feat(signal-store): signal store: specs
mini-rx Jul 3, 2023
825b996
feat(signal-store): signal store: specs
mini-rx Jul 3, 2023
fe1f692
feat(signal-store): signal store: specs
mini-rx Jul 5, 2023
72a06f7
feat(signal-store): signal store: specs
mini-rx Jul 5, 2023
7665723
feat(signal-store): signal store: specs fix demo src link
mini-rx Jul 5, 2023
05caa4d
feat(signal-store): signal store: providers
mini-rx Jul 9, 2023
fac802e
feat(signal-store): signal store: ng-modules tests
mini-rx Jul 10, 2023
19db071
feat(signal-store): signal store: ng-modules tests
mini-rx Jul 10, 2023
a8e694e
feat(signal-store): signal store: providers tests
mini-rx Jul 10, 2023
db1aad4
feat(signal-store): signal store: create reducer inside initStore
mini-rx Jul 12, 2023
8f3950e
feat(signal-store): signal store: package json
mini-rx Jul 12, 2023
97c4b41
Merge pull request #196 from spierala/signal-store--providers
spierala Jul 12, 2023
e78e890
feat(signal-store): signal store: remove demo code
mini-rx Jul 14, 2023
b2ea321
feat(signal-store): signal store: adjust build all
mini-rx Jul 14, 2023
160018f
feat(signal-store): signal store: cleanups
mini-rx Jul 14, 2023
baa19de
feat(signal-store): signal store: cleanups
mini-rx Jul 14, 2023
17e9894
feat(signal-store): signal store: cleanups public API
mini-rx Jul 14, 2023
5850e87
feat(signal-store): signal store: refactor hasOwnProperty
mini-rx Sep 11, 2023
ef3ecbc
feat(signal-store): signal store: small refactors and cleanups
mini-rx Sep 11, 2023
9555778
feat(signal-store): signal store: select with default equality fn
mini-rx Sep 11, 2023
0b3ed25
feat(signal-store): signal store: ES2021
mini-rx Sep 11, 2023
094de84
feat(signal-store): signal store: ES2022
mini-rx Sep 11, 2023
b99e727
feat(signal-store): signal store: connect method
mini-rx Sep 18, 2023
ec6744d
feat(signal-store): signal store: connect method, refactor actions
mini-rx Sep 22, 2023
7fcb5d7
feat(signal-store): signal store: connect method, refactor actions
mini-rx Sep 24, 2023
1aa4459
feat(signal-store): common
mini-rx Oct 6, 2023
784920b
feat(signal-store): common: refactor actions, tests
mini-rx Oct 9, 2023
ebb1fdd
feat(signal-store): common: refactor actions, tests
mini-rx Oct 9, 2023
a61309f
feat(signal-store): common: tests: combineReducers
mini-rx Oct 9, 2023
a1fc51e
feat(signal-store): common: tests: ActionsOnQueue
mini-rx Oct 9, 2023
462a729
feat(signal-store): common: tests: createRxEffect
mini-rx Oct 9, 2023
b9a3a37
feat(signal-store): common: tests: deepFreeze, defaultEffectsErrorHan…
mini-rx Oct 10, 2023
6871420
feat(signal-store): common: tests
mini-rx Oct 10, 2023
f04c081
feat(signal-store): common: tests
mini-rx Oct 10, 2023
f2b2454
feat(signal-store): common: tests
mini-rx Oct 10, 2023
2c6d7da
feat(signal-store): common: tests: logger extension
mini-rx Oct 12, 2023
f591624
feat(signal-store): common: tests: logger extension, immutable ext
mini-rx Oct 12, 2023
8315169
feat(signal-store): common: tests: undo extension etx
mini-rx Oct 13, 2023
d95b6f8
feat(signal-store): common: tests: redux devtools
mini-rx Oct 13, 2023
c1663a8
feat(signal-store): common: tests
mini-rx Oct 13, 2023
5b450f5
feat(signal-store): common
mini-rx Oct 13, 2023
b9b854e
feat(signal-store): common: reducerManager
mini-rx Oct 13, 2023
7e15160
feat(signal-store): common: createActionsOnQueue
mini-rx Oct 13, 2023
8cafb14
feat(signal-store): common: selectableSignalState
mini-rx Oct 13, 2023
1a790a2
feat(signal-store): common: createBaseStore
mini-rx Oct 13, 2023
3153682
feat(signal-store): common: createBaseStore, component store config
mini-rx Oct 14, 2023
a9c0e78
feat(signal-store): common
mini-rx Oct 18, 2023
a9f26e5
feat(signal-store): common
mini-rx Oct 20, 2023
bbf40eb
feat(signal-store): common
mini-rx Oct 23, 2023
5b0611d
feat(signal-store): common
mini-rx Oct 24, 2023
d5b551e
feat(signal-store): common: ComponentStoreLike interface
mini-rx Oct 24, 2023
ab70153
feat(signal-store): common
mini-rx Oct 24, 2023
61cb939
Merge pull request #203 from spierala/signal-store--common
spierala Oct 24, 2023
1c0289e
feat(signal-store): remove takeUntilDestroyed, use classic sub.add
mini-rx Oct 24, 2023
58791d4
feat(signal-store): package versions++, fix import
mini-rx Oct 24, 2023
e3be99a
Merge branch 'signal-store--common' into signal-store
mini-rx Oct 24, 2023
2a46759
Revert "feat(signal-store): remove takeUntilDestroyed, use classic su…
mini-rx Oct 24, 2023
b177427
feat(signal-store): optimise imports
mini-rx Oct 25, 2023
4005107
feat(signal-store): reimplement toObservable with Subject instead of …
mini-rx Oct 25, 2023
b7420e8
feat(signal-store): subsink
mini-rx Oct 27, 2023
f733196
feat(signal-store): rx effect injector
mini-rx Oct 27, 2023
50af7b4
feat(signal-store): improve tests
mini-rx Nov 1, 2023
ee50ec0
feat(signal-store): improve tests
Nov 4, 2023
4e0d287
feat(signal-store): improve tests
mini-rx Nov 10, 2023
d12bf4c
feat(signal-store): improve tests
mini-rx Nov 17, 2023
b5060a3
feat(signal-store): deps
mini-rx Nov 19, 2023
e83f65c
feat(signal-store): inc dep versions
mini-rx Nov 24, 2023
f6fcff6
feat(signal-store, common): more lightweight injection tokens
mini-rx Nov 28, 2023
139ab38
feat(signal-store, common): better component store config error
mini-rx Nov 28, 2023
0a87042
feat(signal-store, common): reduce bundle size
mini-rx Nov 28, 2023
a41044f
feat(common): isFunction
mini-rx Nov 28, 2023
7b3f9e5
feat(common): easier calculate extensions and more minor bundle size …
mini-rx Nov 28, 2023
db082fa
feat(signal-store): rename dispatcher => updateState
mini-rx Nov 28, 2023
369c177
fix(common): add reducer manager default reducer
mini-rx Dec 1, 2023
a8dd587
feat(common): improve test describe
portofantwerpbruges Dec 15, 2023
6996eac
chore(all): relax jest dependencies
portofantwerpbruges Dec 15, 2023
d47b646
chore(all): use yarn
mini-rx Dec 16, 2023
511d9dd
chore(all): use yarn, node 18
mini-rx Dec 16, 2023
cbbf12d
Merge remote-tracking branch 'origin/master' into signal-store
mini-rx Jan 4, 2024
42f1a14
feat(common): better typing of reducer
mini-rx Jan 6, 2024
2c69c39
feat(common): better comment
mini-rx Jan 6, 2024
c306f7b
feat(common): remove not useful comments
mini-rx Jan 6, 2024
c369b4f
feat(common): retryAttemptsLeft
mini-rx Jan 6, 2024
0cefb28
Merge branch 'master' of github.com:spierala/mini-rx-store into signa…
mini-rx Jan 6, 2024
52b53e4
refactor(common, signal-store): use UpdateStateCallback
mini-rx Jan 15, 2024
cd90166
refactor(signal-store): remove obsolete wrapper fn for isSignal
mini-rx Jan 15, 2024
6008062
docs(common, signal-store): add comments
mini-rx Jan 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -24,8 +24,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: yarn install --frozen-lockfile
- run: npm run build:all
- run: npm run test:mini-rx-store
- run: npm run test:mini-rx-store-ng
- run: yarn run build:all
- run: yarn run test:all
env:
CI: true
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/coverage
*.md
/docs

.angular
4 changes: 4 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ See the file for details.
This repository includes a file "deep-freeze.ts" originally copied from
https://github.com/jsdf/deep-freeze/blob/v1.1.1/index.js, public domain licensed.
See the file for details.

This repository includes a file "mini-rx-to-observable.ts" originally copied from
https://github.com/angular/angular/blob/16.2.10/packages/core/rxjs-interop/src/to_observable.ts, MIT style licensed.
See the file for details.
30 changes: 15 additions & 15 deletions apps/mini-rx-angular-demo-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["src/plugins/index.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"no-undef": "off"
}
}
]
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["src/plugins/index.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"no-undef": "off"
}
}
]
}
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getJestProjects } = require('@nx/jest');
import { getJestProjects } from '@nx/jest';

export default {
projects: getJestProjects(),
Expand Down
18 changes: 18 additions & 0 deletions libs/common/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions libs/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# common
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better README still has to come in another PR.


This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build common` to build the library.

## Running unit tests

Run `nx test common` to execute the unit tests via [Jest](https://jestjs.io).
17 changes: 17 additions & 0 deletions libs/common/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable */
export default {
displayName: 'common',
preset: '../../jest.preset.js',
globals: {},
transform: {
'^.+\\.[tj]s$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/common',
testRunner: 'jest-jasmine2',
};
8 changes: 8 additions & 0 deletions libs/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@mini-rx/common",
"version": "0.0.8",
"peerDependencies": {
"rxjs": "^6.4.0 || ^7.0.0"
},
"sideEffects": false
}
56 changes: 56 additions & 0 deletions libs/common/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "common",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/common/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/common",
"main": "libs/common/src/index.ts",
"tsConfig": "libs/common/tsconfig.lib.json",
"assets": [],
"project": "libs/common/package.json",
"format": ["esm", "cjs"],
"globals": [
{
"global": "Rx",
"moduleId": "rxjs"
},
{
"global": "Rx",
"moduleId": "rxjs/operators"
}
]
}
},
"publish": {
"command": "node tools/scripts/publish.mjs common {args.ver} {args.tag}",
"dependsOn": ["build"]
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/common/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/common/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
}
},
"tags": []
}
50 changes: 50 additions & 0 deletions libs/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export { miniRxNameSpace } from './lib/constants';
export { createSubSink } from './lib/sub-sink';
export { createMiniRxActionType, OperationType } from './lib/create-mini-rx-action-type';
export { combineMetaReducers } from './lib/combine-meta-reducers';
export { miniRxError } from './lib/mini-rx-error';
export { sortExtensions } from './lib/sort-extensions';
export { mapResponse } from './lib/map-response';
export { tapResponse } from './lib/tap-response';
export { ofType } from './lib/of-type';
export { createActionsOnQueue } from './lib/actions-on-queue';
export { defaultEffectsErrorHandler } from './lib/default-effects-error-handler';
export {
createRxEffect,
hasEffectMetaData,
HasEffectMetadata,
EffectConfig,
EFFECT_METADATA_KEY,
} from './lib/create-rx-effect';
export { LoggerExtension } from './lib/extensions/logger/logger.extension';
export { UndoExtension } from './lib/extensions/undo/undo-extension';
export { undo } from './lib/extensions/undo/undo';
export { ImmutableStateExtension } from './lib/extensions/immutable-state/immutable-state.extension';
export {
AbstractReduxDevtoolsExtension,
ReduxDevtoolsOptions,
} from './lib/extensions/redux-devtools/abstract-redux-devtools-extension';
export { createFeatureStoreReducer } from './lib/create-feature-store-reducer';
export { createComponentStoreReducer } from './lib/create-component-store-reducer';
export { generateId } from './lib/generate-id';
export { calculateExtensions } from './lib/calculate-extensions';
export { createReducerManager, ReducerManager } from './lib/reducer-manager';
export { componentStoreConfig } from './lib/component-store-config';
export { ExtensionId } from './lib/enums';
export {
Action,
Actions,
FeatureStoreConfig,
Reducer,
StateOrCallback,
MiniRxAction,
StoreExtension,
StoreConfig,
FeatureConfig,
MetaReducer,
ComponentStoreConfig,
ComponentStoreExtension,
AppState,
ReducerDictionary,
ReducerState,
} from './lib/models';
34 changes: 34 additions & 0 deletions libs/common/src/lib/actions-on-queue.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createActionsOnQueue } from './actions-on-queue';
import { take } from 'rxjs';

describe('ActionsOnQueue', () => {
it('should dispatch actions', () => {
const spy = jest.fn();

const actionsOnQueue = createActionsOnQueue();
actionsOnQueue.actions$.subscribe(spy);

const action = { type: 'someAction' };
actionsOnQueue.dispatch(action);

expect(spy).toHaveBeenCalledWith(action);
});
it('should queue actions', () => {
// Without queueScheduler this test would fail because of stack overflow (Read more here: https://blog.cloudboost.io/so-how-does-rx-js-queuescheduler-actually-work-188c1b46526e)

const callLimit = 5000;

const actionsOnQueue = createActionsOnQueue();

const spy = jest.fn().mockImplementation(() => {
// Every received action dispatches another action
actionsOnQueue.dispatch({ type: 'someAction' });
});

actionsOnQueue.actions$.pipe(take(callLimit)).subscribe(spy);

actionsOnQueue.dispatch({ type: 'someInitialAction' }); // Dispatch an action to start the whole thing

expect(spy).toHaveBeenCalledTimes(callLimit);
});
});
16 changes: 16 additions & 0 deletions libs/common/src/lib/actions-on-queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { queueScheduler, Subject, observeOn } from 'rxjs';
import { Action } from './models';

export function createActionsOnQueue() {
const actionsSource = new Subject<Action>();

return {
actions$: actionsSource.asObservable().pipe(
observeOn(queueScheduler) // Prevent stack overflow: https://blog.cloudboost.io/so-how-does-rx-js-queuescheduler-actually-work-188c1b46526e
),
dispatch: <T extends Action>(action: T): T => {
actionsSource.next(action);
return action;
},
};
}
33 changes: 33 additions & 0 deletions libs/common/src/lib/beautify-action.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { beautifyAction } from './beautify-action';
import { MiniRxAction } from './models';
import { createMiniRxActionType, OperationType } from './create-mini-rx-action-type';

describe('beautifyAction', () => {
it('should remove extra fields from FeatureStore/ComponentStore Actions', () => {
const csAction: MiniRxAction<any> = {
type: createMiniRxActionType(OperationType.SET_STATE, 'todos'),
stateOrCallback: {},
};

expect(beautifyAction(csAction)).toEqual({
type: '@mini-rx/todos/set-state',
payload: {},
});

const fsAction: MiniRxAction<any> = {
type: createMiniRxActionType(OperationType.SET_STATE, 'todos'),
stateOrCallback: {},
featureId: 'someFeatureId',
};

expect(beautifyAction(fsAction)).toEqual({
type: '@mini-rx/todos/set-state',
payload: {},
});
});
it('should not touch other normal Actions', () => {
const action = { type: 'someAction' };

expect(beautifyAction(action)).toBe(action);
});
});
12 changes: 12 additions & 0 deletions libs/common/src/lib/beautify-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Action, MiniRxAction } from '../lib/models';
import { isMiniRxAction } from './is-mini-rx-action';

// Only display type and payload in the LoggingExtension and Redux DevTools
export function beautifyAction(action: Action | MiniRxAction<any>): Action {
return isMiniRxAction(action)
? {
type: action.type,
payload: action.stateOrCallback,
}
: action;
}
13 changes: 13 additions & 0 deletions libs/common/src/lib/calc-next-state.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { calcNextState } from './calc-next-state';

describe('calcNextState', () => {
it('should calculate next state', () => {
const currentState = { count: 1 };
expect(calcNextState(currentState, { count: 2 })).toEqual({ count: 2 });

// Witch callback
expect(calcNextState(currentState, (state) => ({ count: state.count + 2 }))).toEqual({
count: 3,
});
});
});
9 changes: 9 additions & 0 deletions libs/common/src/lib/calc-next-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { StateOrCallback } from './models';
import { isFunction } from './is-function';

export function calcNextState<T>(state: T, stateOrCallback: StateOrCallback<T>): T {
return {
...state,
...(isFunction(stateOrCallback) ? stateOrCallback(state) : stateOrCallback), // new partial state
};
}
Loading
Loading