Skip to content
New issue

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

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

Already on GitHub? # to your account

Add disableTracking to StoreConfig #519

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docs/docs/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ See [caching support](../additional/cache) section.
### `idKey`
A custom `idKey` for `EntityStore` - see [EntityId](../entities/entity-store#entity-id) section.

### `disableTracking`
Option to disable devtools tracking.


:::info
You can also provide the `options` in the constructor:

Expand Down
13 changes: 12 additions & 1 deletion libs/akita/src/__tests__/devtools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { capitalize } from '../lib/capitalize';
import { akitaDevtools } from '../lib/devtools';
import { Store } from '../lib/store';
import { applyTransaction } from '../lib/transaction';
import { TodosStore } from './setup';
import { TodosStore, DisabledTrackingConfigStore } from './setup';

function buildActionTypeString(store: Store<any>, type: string) {
return `[${capitalize(store.storeName)}] - ${type}`;
Expand Down Expand Up @@ -201,6 +201,17 @@ describe('DevTools', () => {
expect(connectMock.send.mock.calls[0][0]['type']).toEqual(expect.stringContaining(buildActionTypeString(store, `Custom Action`)));
});

it('should log only if disableTracking is not true', function () {
connectMock.send.mockReset();
const noTrackingStoreConfig = new DisabledTrackingConfigStore();
const noTrackingStoreOptions = new Store({}, { disableTracking: true });

noTrackingStoreConfig.setLoading();
noTrackingStoreOptions.setLoading();

expect(connectMock.send.mock.calls.length).toBe(0);
});

afterEach(() => {
store.destroy();
connectMock.send.mockReset();
Expand Down
3 changes: 3 additions & 0 deletions libs/akita/src/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,6 @@ export function createWidget(id) {
}

export const tick = () => new Promise(process.nextTick);

@StoreConfig({ name: 'disabledTrackingConfig', disableTracking: true })
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer not using devtools configuration in the store. It should be in the devtools options.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, so my idea was to enable using Akita in libraries for complex components. This way I could disable it by default and the application developer wouldn't see them unless he chose to through let's say component's module configuration. I suppose you want me to add storeBlacklist to devtools options? In that case i should do it by providing storeBlacklistPattern since i will be relying on storeName's prefix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add storeBlacklist and support both strings and cb function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And add yourself to the contributors' list

Copy link
Author

Choose a reason for hiding this comment

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

Ok, deal.

Copy link
Author

Choose a reason for hiding this comment

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

I'll create a new PR

export class DisabledTrackingConfigStore extends EntityStore<State> {}
2 changes: 1 addition & 1 deletion libs/akita/src/lib/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function akitaDevtools(ngZoneOrOptions?: NgZoneLike | Partial<DevtoolsOpt
let appState = {};

const isAllowed = (storeName) => {
if (!storesWhitelist.length) {
if (!storesWhitelist.length && !__stores__[storeName].disabledTracking) {
return true;
}

Expand Down
5 changes: 5 additions & 0 deletions libs/akita/src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ export class Store<S = any> {
return isDefined(this.config.resettable) ? this.config.resettable : this.options.resettable;
}

// @internal
get disabledTracking() {
return isDefined(this.config.disableTracking) ? this.config.disableTracking : this.options.disableTracking;
}

// @internal
_setState(newState: ((state: Readonly<S>) => S) | S, _dispatchAction = true) {
if (isFunction(newState)) {
Expand Down
3 changes: 2 additions & 1 deletion libs/akita/src/lib/storeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type StoreConfigOptions = {
deepFreezeFn?: (o: any) => any;
idKey?: string;
producerFn?: AkitaConfig['producerFn'];
disableTracking?: boolean;
};

export type UpdatableStoreConfigOptions = {
Expand All @@ -16,7 +17,7 @@ export type UpdatableStoreConfigOptions = {
export const configKey = 'akitaConfig';

export function StoreConfig(metadata: StoreConfigOptions) {
return function(constructor: Function) {
return function (constructor: Function) {
constructor[configKey] = { idKey: 'id' };

for (let i = 0, keys = Object.keys(metadata); i < keys.length; i++) {
Expand Down