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

v2.0.0 #33

Merged
merged 141 commits into from
Sep 9, 2021
Merged
Changes from 1 commit
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
9874a8a
feat(extensions): started action extension
andrewcourtice Jun 16, 2021
39ebeac
Merge branch 'main' of https://github.com/andrewcourtice/harlem into …
andrewcourtice Jun 16, 2021
58f2db2
fix(extensions): fixed typing on actions extension
andrewcourtice Jul 13, 2021
81d07d1
Merge branch 'main' of https://github.com/andrewcourtice/harlem into …
andrewcourtice Jul 31, 2021
48634d5
chore: fixed typing in test files
andrewcourtice Jul 31, 2021
89586df
refactor(core): cleaned up whitespace
andrewcourtice Jul 31, 2021
81fe605
fix(extensions): fixed actions extension test failing
andrewcourtice Jul 31, 2021
c586e6a
feat(utilities): added task
andrewcourtice Aug 1, 2021
c9da2f1
feat(extensions): added cancellation to actions
andrewcourtice Aug 1, 2021
0a76ece
chore: added eslint and fixed linting errors
andrewcourtice Aug 1, 2021
fdf5b11
chore: fixed typing in test files
andrewcourtice Aug 1, 2021
d7d366c
chore: eslint fixes for js files
andrewcourtice Aug 2, 2021
ce27577
chore: fixed some typing and linting
andrewcourtice Aug 2, 2021
eb102a7
refactor: started moving some plugins over to be extensions
andrewcourtice Aug 2, 2021
202025c
feat(core): added provider api
andrewcourtice Aug 2, 2021
a4bc9a5
fix(extensions): fixed transaction extension
andrewcourtice Aug 2, 2021
e8bcd49
fix(core): fixed typings
andrewcourtice Aug 3, 2021
744ba80
chore: changed output file names
andrewcourtice Aug 3, 2021
a343a8a
feat(utilities): added trace function
andrewcourtice Aug 4, 2021
19a6335
refactor(plugins): fixed ssr event literal
andrewcourtice Aug 4, 2021
2835c45
feat(extensions): added trace extension
andrewcourtice Aug 4, 2021
b664f88
refactor: cleaned up manual build process and used tsup
andrewcourtice Aug 4, 2021
d70a241
chore: updated dependencies
andrewcourtice Aug 4, 2021
2b02242
fix(extensions): fixed type exports
andrewcourtice Aug 4, 2021
9902107
feat(core): added effect scope to store
andrewcourtice Aug 4, 2021
2dff71f
feat(core): added event to signal devtools update
andrewcourtice Aug 4, 2021
2fb22d1
feat(extensions): added devtools update to lazy extension
andrewcourtice Aug 4, 2021
8413fb6
feat(plugins): updated devtools to support new store registration format
andrewcourtice Aug 4, 2021
69a26fb
chore: update yarn.lock
andrewcourtice Aug 4, 2021
a482cdb
Merge branch 'main' of https://github.com/andrewcourtice/harlem into …
andrewcourtice Aug 4, 2021
cd268a4
refactor(core): changed mutation hook name and improved destroyed stores
andrewcourtice Aug 5, 2021
8796aef
fix(devtools): fixed event hook
andrewcourtice Aug 5, 2021
7989b82
feat(utilities): added to and from object utils
andrewcourtice Aug 5, 2021
2b6e892
fix(storage): fixed event hook name
andrewcourtice Aug 5, 2021
2d9cbda
feat(lazy): added registration type
andrewcourtice Aug 5, 2021
bdfef62
refactor(trace): change node field names
andrewcourtice Aug 5, 2021
1ed86cd
feat(history): added basic history extension
andrewcourtice Aug 5, 2021
0afd28a
refactor: moved some packages around
andrewcourtice Aug 5, 2021
17c742e
feat(app): started updating the demo app
andrewcourtice Aug 5, 2021
45665ab
feat(app): further work on demo app
andrewcourtice Aug 6, 2021
f423bac
Merge branch 'main' of https://github.com/andrewcourtice/harlem into …
andrewcourtice Aug 6, 2021
f3fe32e
chore: test broken demo
andrewcourtice Aug 6, 2021
be665a1
chore: more testing
andrewcourtice Aug 6, 2021
5e8c7d4
feat(app): many little improvements to demo
andrewcourtice Aug 6, 2021
fe30a17
refactor: ensure consistent sender id for events
andrewcourtice Aug 7, 2021
b9e198a
chore: update yarn.lock
andrewcourtice Aug 7, 2021
4766ee5
Merge branch 'main' of https://github.com/andrewcourtice/harlem into …
andrewcourtice Aug 7, 2021
9e581b6
chore: updated packages
andrewcourtice Aug 7, 2021
f7e2cfb
chore: fixed linting issues
andrewcourtice Aug 7, 2021
f42a5c2
v2.0.0-alpha.0
andrewcourtice Aug 7, 2021
9a28b89
chore: updated peer dependency versions
andrewcourtice Aug 7, 2021
7d84eaa
chore: updated packages
andrewcourtice Aug 8, 2021
197bcc8
docs: started action docs
andrewcourtice Aug 8, 2021
9e48fe9
refactor(core): minor variable name changes
andrewcourtice Aug 8, 2021
8dfd68e
fix(actions): use provided payload for action body
andrewcourtice Aug 8, 2021
3981476
docs(action): added action status docs
andrewcourtice Aug 8, 2021
ace1549
docs(action): minor fixes to terminology
andrewcourtice Aug 8, 2021
23c8bc6
docs(action): updated action extension docs
andrewcourtice Aug 9, 2021
cc6bf6b
docs(history): updated history extension docs
andrewcourtice Aug 9, 2021
7fa0b95
docs(lazy): updated lazy extension docs
andrewcourtice Aug 9, 2021
7eec859
docs(history): minor terminology changes
andrewcourtice Aug 9, 2021
c7708bc
docs(reset): added docs for the reset extension
andrewcourtice Aug 9, 2021
39a817a
docs(snapshot): added docs for the snapshot extension
andrewcourtice Aug 9, 2021
357f510
docs(snapshot): highlighted readonly state
andrewcourtice Aug 9, 2021
4b7b7a8
docs: updated core readme doc
andrewcourtice Aug 9, 2021
6445c10
docs: updated some code examples
andrewcourtice Aug 9, 2021
6fba994
docs(history): added example options
andrewcourtice Aug 9, 2021
2e27e53
docs(storage): started storage docs
andrewcourtice Aug 9, 2021
b45bf47
docs: fixed typo
andrewcourtice Aug 9, 2021
6eaa05b
chore: updated packages
andrewcourtice Aug 9, 2021
99f1421
refactor(app): moved styles to assets and added favicon
andrewcourtice Aug 9, 2021
61179db
docs: updated demo app link
andrewcourtice Aug 9, 2021
124c317
feat(app): updated demo app
andrewcourtice Aug 10, 2021
ca345e6
fix(app): fixed font references
andrewcourtice Aug 10, 2021
84e6f64
feat(app): added theme
andrewcourtice Aug 10, 2021
092ecc8
feat(app): added storage sync
andrewcourtice Aug 11, 2021
97dc773
docs: started updating vuepress docs
andrewcourtice Aug 11, 2021
77ad7c0
feat(storage): added exclude option and clearStorage
andrewcourtice Aug 11, 2021
452a651
chore: updated yarn.lock
andrewcourtice Aug 11, 2021
86310f6
docs: minor order change in readme
andrewcourtice Aug 11, 2021
34b32ad
chore: update eslint rules
andrewcourtice Aug 11, 2021
176b41e
fix(action): fixed action abort error type
andrewcourtice Aug 11, 2021
de61226
fix(app): fixed modal attrs
andrewcourtice Aug 11, 2021
c08415c
fix(history): fixed command order for undo
andrewcourtice Aug 11, 2021
2532e65
docs: further updates to docs
andrewcourtice Aug 11, 2021
c86c1c0
docs: fixed link to harlem docs
andrewcourtice Aug 11, 2021
5f5a29c
fix: fixed vue package version baseline
andrewcourtice Aug 11, 2021
fb160f3
v2.0.0-beta.0
andrewcourtice Aug 11, 2021
4632979
chore: added changelog
andrewcourtice Aug 11, 2021
2448b94
docs: further extensive docs changes
andrewcourtice Aug 12, 2021
04dcc0d
docs: updated main readme
andrewcourtice Aug 12, 2021
e77ee3f
fix(utilities): added support for unwrapping reactives during clone
andrewcourtice Aug 18, 2021
da93d25
fix: fixed package.json config for output
andrewcourtice Aug 18, 2021
86af320
feat(app): added support for user defined theme
andrewcourtice Aug 18, 2021
4f109d0
fix: fixed clone typing
andrewcourtice Aug 18, 2021
3d065cc
v2.0.0-beta.1
andrewcourtice Aug 18, 2021
a8ae1b9
docs: started adding extensions api to docs
andrewcourtice Aug 18, 2021
8f5cbd3
feat(core): added event suppression
andrewcourtice Aug 18, 2021
7dd5622
fix(core): fixed suppress return type
andrewcourtice Aug 19, 2021
268dd93
fix(action): suppress initial write ops to prevent thrashing triggers
andrewcourtice Aug 19, 2021
6151630
fix: allowed comments in tsconfig
andrewcourtice Aug 19, 2021
3b9ddf9
v2.0.0-beta.2
andrewcourtice Aug 19, 2021
fd5cc56
fix(utilities): unref value before testing type for cloning
andrewcourtice Sep 1, 2021
f742a09
docs: simplified table of contents
andrewcourtice Sep 1, 2021
44602b9
test(core): added test for payload producer
andrewcourtice Sep 1, 2021
b310da0
test(core): added store destroy test
andrewcourtice Sep 1, 2021
fa89b78
v2.0.0-beta.3
andrewcourtice Sep 1, 2021
40fb44a
chore(extensions): rmeoved unused types
andrewcourtice Sep 5, 2021
9d8e71b
feat(utilities): added top-level ignore pattern to overwrite
andrewcourtice Sep 5, 2021
3501915
feat(extensions): added branch function to reset
andrewcourtice Sep 5, 2021
633076b
v2.0.0-beta.4
andrewcourtice Sep 5, 2021
c1e4b49
fix(utilities): fixed overwrite ignore logic
andrewcourtice Sep 6, 2021
b86f63c
v2.0.0-beta.5
andrewcourtice Sep 6, 2021
5930537
fix(core): notify devtools when store is created/destroyed
andrewcourtice Sep 6, 2021
7af6778
fix(extensions): added sender constant to lazy extension
andrewcourtice Sep 6, 2021
9deba20
feat(extensions): added state reset method to action extension
andrewcourtice Sep 6, 2021
6cedfe6
v2.0.0-beta.6
andrewcourtice Sep 6, 2021
97e7203
fix(devtools): send inspector tree on manual devtools update
andrewcourtice Sep 6, 2021
b7efd94
fix(action): return function as devtools value
andrewcourtice Sep 7, 2021
0b282d3
v2.0.0-beta.7
andrewcourtice Sep 7, 2021
974dd80
feat(action): added error states
andrewcourtice Sep 7, 2021
15e102e
chore: updated packages
andrewcourtice Sep 7, 2021
32507bb
docs: updated docs
andrewcourtice Sep 7, 2021
ae388a2
v2.0.0-beta.8
andrewcourtice Sep 7, 2021
101c75f
refactor(core): minor internal type name changes
andrewcourtice Sep 8, 2021
766c6f4
test(core): updated mutation trigger test
andrewcourtice Sep 8, 2021
b58fc6a
feat(action): added action triggers
andrewcourtice Sep 8, 2021
fb698d6
test(action): added action trigger test
andrewcourtice Sep 8, 2021
f851b48
v2.0.0-beta.9
andrewcourtice Sep 8, 2021
da50da3
refactor(core): updated mutation structure
andrewcourtice Sep 8, 2021
98a4787
refactor(action): updated action structure
andrewcourtice Sep 8, 2021
88cab67
feat(transaction): added transaction triggers and mutator helpers
andrewcourtice Sep 8, 2021
c886f3f
docs: updated docs
andrewcourtice Sep 8, 2021
4d4d26e
fix: fixed trigger order
andrewcourtice Sep 8, 2021
b27b1b4
v2.0.0-beta.10
andrewcourtice Sep 8, 2021
6ff7abd
test(core): added event emitter test
andrewcourtice Sep 8, 2021
d241bea
feat(trace): added debug option for logging results
andrewcourtice Sep 8, 2021
d5c4064
docs: updated docs
andrewcourtice Sep 8, 2021
0a6c979
chore: updated readme files
andrewcourtice Sep 8, 2021
3ef1606
fix: fixed internal properties being visible in various areas
andrewcourtice Sep 9, 2021
7f02e69
chore: updated packages
andrewcourtice Sep 9, 2021
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
42 changes: 13 additions & 29 deletions extensions/actions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
Extension,
InternalStore,
createStore,
Mutator
} from '@harlem/core';

@@ -11,33 +9,34 @@ import type {
ActionPredicate,
ActionStoreState,
AddActionInstancePayload,
ComposedAction,
RemoveActionInstancePayload
} from './types';

export * from './types';

export default function actionsExtension<TState>(store: InternalStore<TState>) {

const _store = store as unknown as InternalStore<TState & ActionStoreState>;

store.write('$add-actions', '$actions-extension', state => {
_store.write('$add-actions', '$actions-extension', state => {
state.$actions = {};
});

const addActionInstance = store.mutation<AddActionInstancePayload>('$add-action-instance', (state, payload) => {
const addActionInstance = _store.mutation<AddActionInstancePayload>('$add-action-instance', (state, payload) => {
const {
actionName,
instanceId,
instancePayload
} = payload;

if (!state.$actions[actionName]) {
state.$actions[actionName] = new Map<symbol, any>();
state.$actions[actionName] = new Map<symbol, unknown>();
}

state.$actions[actionName].set(instanceId, instancePayload);
});

const removeActionInstance = store.mutation<RemoveActionInstancePayload>('$remove-action-instance', (state, payload) => {
const removeActionInstance = _store.mutation<RemoveActionInstancePayload>('$remove-action-instance', (state, payload) => {
const {
actionName,
instanceId,
@@ -51,9 +50,9 @@ export default function actionsExtension<TState>(store: InternalStore<TState>) {
});

function action<TPayload, TResult = void>(name: string, body: ActionBody<TState, TPayload, TResult>): Action<TPayload, TResult> {
const mutate = (mutator: Mutator<TState, undefined, void>) => store.write(name, '$actions-extension', mutator);
const mutate = (mutator: Mutator<TState, undefined, void>) => _store.write(name, '$actions-extension', mutator);

const _action = async (payload: TPayload) => {
return (async (payload: TPayload) => {
const id = Symbol(name);

addActionInstance({
@@ -74,35 +73,20 @@ export default function actionsExtension<TState>(store: InternalStore<TState>) {
}

return result;
};

_action.name = name;

return _action as Action<TPayload, TResult>;
}) as Action<TPayload, TResult>;
}

function isActionRunnng<TPayload = any>(name: string, instancePredicate?: ActionPredicate<TPayload>) {
const predicate = instancePredicate || (() => true);
const instances = store.state.$actions[name];
function isActionRunning<TPayload = unknown>(name: string, predicate: ActionPredicate<TPayload> = () => true) {
const instances = _store.state.$actions[name];

return !!instances && Array
.from(instances.values())
.some(payload => predicate(payload));
}

function useAction<TPayload, TResult>(action: Action<TPayload, TResult>): ComposedAction<TPayload, TResult> {
const isRunning = (predicate?: ActionPredicate<TPayload>) => isActionRunnng(action.name, predicate);

return [
action,
isRunning
];
.some(payload => predicate(payload as TPayload));
}

return {
action,
isActionRunnng,
useAction
isActionRunning
};

};
15 changes: 4 additions & 11 deletions extensions/actions/src/types.ts
Original file line number Diff line number Diff line change
@@ -3,25 +3,18 @@ import {
} from '../../../core/dist';

export type ActionBody<TState, TPayload = undefined, TResult = void> = (payload: TPayload, mutator: (mutate: Mutator<TState, undefined, void>) => void) => Promise<TResult>;
//export type Action<TPayload, TResult = void> = undefined extends TPayload ? (payload?: TPayload) => Promise<TResult> : (payload: TPayload) => Promise<TResult>;
export type ActionPredicate<TPayload = any> = (payload?: TPayload) => boolean;
export type Action<TPayload, TResult = void> = undefined extends TPayload ? (payload?: TPayload) => Promise<TResult> : (payload: TPayload) => Promise<TResult>;
export type ActionPredicate<TPayload = unknown> = (payload?: TPayload) => boolean;
export type ComposedAction<TPayload, TResult = void> = [Action<TPayload, TResult>, (predicate: ActionPredicate<TPayload>) => boolean];

export interface Action<TPayload, TResult = void> {
(payload?: TPayload): Promise<TResult>;
name: string
}

export interface ActionStoreState {
$actions: {
[key: string]: Map<symbol, any>;
}
$actions: Record<string, Map<symbol, unknown>>;
}

export interface AddActionInstancePayload {
actionName: string;
instanceId: symbol;
instancePayload?: any;
instancePayload?: unknown;
}

export interface RemoveActionInstancePayload {
30 changes: 24 additions & 6 deletions extensions/actions/test/actions.test.ts
Original file line number Diff line number Diff line change
@@ -2,29 +2,47 @@ import {
createStore
} from '@harlem/core';

import actionsExtension from '../src/index';
import actionsExtension from '../src';

describe('Actions Extension', () => {

test('Performs a root reset', () => {
test('Runs an action', async () => {
const {
action
state,
action,
isActionRunning
} = createStore('test', {
givenName: 'John',
surname: 'Smith'
surname: 'Smith',
age: 28
}, {
extensions: [
actionsExtension
]
});

const loadUserInfo = action('load-user-info', async (id, mutate) => {
const actionName = 'load-user-info';

const loadUserInfo = action(actionName, async (name: string, mutate) => {
return new Promise(resolve => setTimeout(() => {
mutate(state => {
state.
state.givenName = name;
state.age = 26;
});

resolve(true);
}, 300));
});

const promise = loadUserInfo('Jane');

expect(isActionRunning(actionName)).toBe(true);

await promise;

expect(state.givenName).toBe('Jane');
expect(state.age).toBe(26);
expect(isActionRunning(actionName)).toBe(false);
});

});