Skip to content

Commit

Permalink
Remove reseting specific keys
Browse files Browse the repository at this point in the history
  • Loading branch information
samirsilwal committed Oct 20, 2024
1 parent 36649b4 commit a57ab86
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 46 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,7 @@ Note: This is same as `getId();` the difference being it only returns the first
const requestIdentifier = store.getShortId();
```

### reset()

Reset the store or a specific key of the global store.

- `@returns {void}`

```js
store.reset(); // Reset the whole store

store.reset('foo') // It will delete the key foo from store and get will result undefined
```

## Example Projects

Expand Down
2 changes: 1 addition & 1 deletion src/AsyncStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface AsyncStore {
isInitialized: () => boolean;
getId: () => string | undefined;
getShortId: () => string | undefined;
reset: (key?: string) => void;
reset: () => void;
}

export default AsyncStore;
14 changes: 1 addition & 13 deletions src/impl/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,8 @@ export function set(properties: any) {

/**
* Reset the store by removing all values or a specific value by key.
*
* @param {string} key
*/
export function reset(key?: string) {
const store = getStore();

if (key) {
logDomain(`Resetting ${key} in the domain store.`);

delete store[key];

return;
}

export function reset() {
logDomain('Resetting the domain store.');

Check warning on line 106 in src/impl/domain.ts

View check run for this annotation

Codecov / codecov/patch

src/impl/domain.ts#L106

Added line #L106 was not covered by tests

const activeDomain = getActiveDomain();
Expand Down
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,17 @@ export function initialize(adapter: AsyncStoreAdapter = AsyncStoreAdapter.DOMAIN
}

/**
* Reset the store or a specific key.
*
* @param {string} [key]
*/
export function reset(key?: string) {
* Reset the store.
*
* */
export function reset() {
if (!isInitialized()) {
throw new Error('Async store not initialized.');
}

coreLog(`Resetting store or key = ${key}`);
coreLog(`Resetting the store`);

Check warning on line 127 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L127

Added line #L127 was not covered by tests

getInstance(initializedAdapter).reset(key);
getInstance(initializedAdapter).reset();

Check warning on line 129 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L129

Added line #L129 was not covered by tests
}

/**
Expand Down
15 changes: 0 additions & 15 deletions test/domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,21 +504,6 @@ describe('store: [adapter=DOMAIN]', () => {

expect(globalStore.isInitialized()).to.equal(false);
});

it('should reset the store by removing a specific value by key', (done) => {
const callback = () => {
globalStore.set({ foo: 'foo', bar: 'bar' });

globalStore.reset('foo');

expect(globalStore.get('foo')).to.equal(undefined);
expect(globalStore.get('bar')).to.equal('bar');

done();
};

globalStore.initialize(adapter)(callback);
});
});

describe('Test Cases:', () => {
Expand Down

0 comments on commit a57ab86

Please sign in to comment.