Skip to content
Draft
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
78 changes: 0 additions & 78 deletions src/area-chart/async-store/__tests__/async-store.test.ts

This file was deleted.

90 changes: 3 additions & 87 deletions src/area-chart/async-store/index.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { useLayoutEffect, useState } from 'react';
import { unstable_batchedUpdates } from 'react-dom';

import { usePrevious } from '../../internal/hooks/use-previous';

type Selector<S, R> = (state: S) => R;
type Listener<S> = (state: S, prevState: S) => void;

export interface ReadonlyAsyncStore<S> {
get(): S;
subscribe<R>(selector: Selector<S, R>, listener: Listener<S>): () => void;
unsubscribe(listener: Listener<S>): void;
}

export default class AsyncStore<S> implements ReadonlyAsyncStore<S> {
_state: S;
_listeners: [Selector<S, unknown>, Listener<S>][] = [];

constructor(state: S) {
this._state = state;
}

get(): S {
return this._state;
}

set(cb: (state: S) => S): void {
const prevState = this._state;
const newState = cb(prevState);

this._state = newState;

unstable_batchedUpdates(() => {
for (const [selector, listener] of this._listeners) {
if (selector(prevState) !== selector(newState)) {
listener(newState, prevState);
}
}
});
}

subscribe<R>(selector: Selector<S, R>, listener: Listener<S>): () => void {
this._listeners.push([selector, listener]);

return () => this.unsubscribe(listener);
}

unsubscribe(listener: Listener<S>): void {
for (let index = 0; index < this._listeners.length; index++) {
const [, storedListener] = this._listeners[index];

if (storedListener === listener) {
this._listeners.splice(index, 1);
break;
}
}
}
}

export function useReaction<S, R>(store: ReadonlyAsyncStore<S>, selector: Selector<S, R>, effect: Listener<R>): void {
useLayoutEffect(
() => {
const unsubscribe = store.subscribe(selector, (newState, prevState) =>
effect(selector(newState), selector(prevState))
);
return unsubscribe;
},
// ignoring selector and effect as they are expected to stay constant
// eslint-disable-next-line react-hooks/exhaustive-deps
[store]
);
}

export function useSelector<S, R>(store: ReadonlyAsyncStore<S>, selector: Selector<S, R>): R {
const [state, setState] = useState<R>(selector(store.get()));

useReaction(store, selector, newState => {
setState(newState);
});

// When store changes we need the state to be updated synchronously to avoid inconsistencies.
const prevStore = usePrevious(store);
if (prevStore !== null && prevStore !== store) {
return selector(store.get());
}

return state;
}
// Moved to @cloudscape-design/component-toolkit (cloudscape-design/component-toolkit#242).
export { default } from '@cloudscape-design/component-toolkit/internal/async-store';

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / quick-build (React 18)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / quick-build (React 16)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / release / release

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / build (React 18) / build

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / build / build

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Build components

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 2/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 1/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (4/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 4/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (6/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 1/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (5/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components motion tests (React 18)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 4/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components unit tests

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (3/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 3/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (1/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 2/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (2/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 5 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 3/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.
export * from '@cloudscape-design/component-toolkit/internal/async-store';

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / quick-build (React 18)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / quick-build (React 16)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / release / release

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / build (React 18) / build

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / build / build

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Build components

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 2/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 1/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (4/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 4/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (6/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 1/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (5/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components motion tests (React 18)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 4/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components unit tests

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (3/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 3/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (1/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 16, shard 2/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components accessibility tests shards (2/6)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.

Check failure on line 6 in src/area-chart/async-store/index.ts

View workflow job for this annotation

GitHub Actions / dry-run / Components integration tests shards (React 18, shard 3/4)

Cannot find module '@cloudscape-design/component-toolkit/internal/async-store' or its corresponding type declarations.
134 changes: 0 additions & 134 deletions src/table/table-role/__integ__/grid-navigation.test.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/table/table-role/__integ__/page-object.ts

This file was deleted.

This file was deleted.

Loading
Loading