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

Fix history extension mid mutation skip #84

Merged
merged 3 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,31 @@ on:
jobs:

build_and_test:
name: Build and Test Harlem
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3

- name: Prepare NodeJS
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16.x

# Get yarn cache directory path
- name: Get Yarn Cache Path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- uses: actions/cache@v2
# Node module and yarn cache
- name: Yarn Cache
uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-harlem-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
${{ runner.os }}-harlem-

- name: Install Dependencies
run: yarn install
Expand All @@ -43,7 +48,7 @@ jobs:
run: yarn test

- name: Upload Build Artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: |
Expand All @@ -61,7 +66,7 @@ jobs:
# reporter: jest-junit

- name: Upload Test Results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: test-results
path: test-results.xml
19 changes: 12 additions & 7 deletions .github/workflows/publish-demo-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@ on:
jobs:

build_and_publish:
name: Build and Publish Demo App
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3

- name: Prepare NodeJS
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16.x

# Get yarn cache directory path
- name: Get Yarn Cache Path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- uses: actions/cache@v2
# Node module and yarn cache
- name: Yarn Cache
uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-harlem-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
${{ runner.os }}-harlem-

- name: Install Dependencies
run: yarn install
Expand All @@ -43,7 +48,7 @@ jobs:
# please check out the docs of the workflow for more details
# @see https://github.com/crazy-max/ghaction-github-pages
- name: Deploy to GitHub Pages
uses: crazy-max/ghaction-github-pages@v2
uses: crazy-max/ghaction-github-pages@v3
with:
target_branch: demo
build_dir: app/dist
Expand Down
7 changes: 0 additions & 7 deletions app/src/stores/app/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import {
mutation,
} from './store';

import type {
ClockType,
Theme,
} from './types';

export const setTheme = mutation(MUTATIONS.setTheme, (state, theme: Theme) => state.theme = theme);
export const updateTime = mutation(MUTATIONS.updateTime, state => state.time = new Date());
export const setClockType = mutation(MUTATIONS.setClockType, (state, type: ClockType) => state.clockType = type);
export const addClocks = mutation(MUTATIONS.addClocks, (state, timezones: string | string[]) => state.clocks = state.clocks.concat(timezones));
export const removeClock = mutation(MUTATIONS.removeClock, (state, timezone: string) => state.clocks = state.clocks.filter(tz => tz !== timezone));
26 changes: 19 additions & 7 deletions extensions/history/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,19 @@ export default function historyExtension<TState extends BaseState>(options?: Par

return (store: InternalStore<TState>) => {
store.register('extensions', 'history', () => _options);
store.register('history', 'details', () => ({
canUndo: canUndo(),
canRedo: canRedo(),
groups: historyState.groups,
}));
store.register('history', 'groups', () => Object
.entries(historyState.groups)
.reduce((output, [key, { history, position }]) => {
output[key] = {
history,
position,
canUndo: canUndo(key),
canRedo: canRedo(key),
};

return output;
}, {} as Record<string, unknown>)
);

const {
startTrace,
Expand Down Expand Up @@ -126,7 +134,11 @@ export default function historyExtension<TState extends BaseState>(options?: Par
'deleteProperty',
]);

const listener = onTraceResult(result => historyState.results.push(result));
const listener = onTraceResult(result => {
if (trackingListener) {
historyState.results.push(result);
}
});

store.once(CORE_EVENTS.mutation.after, () => {
stopTrace();
Expand All @@ -138,7 +150,7 @@ export default function historyExtension<TState extends BaseState>(options?: Par
}

function stopHistoryTracking() {
trackingListener = (trackingListener?.dispose(), undefined);
trackingListener = trackingListener?.dispose() || undefined;
}

function skipHistoryTracking<TResult = void>(callback: () => TResult) {
Expand Down