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

Rename query events #127

Merged
merged 4 commits into from
Aug 5, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/runConfigurations/All_Tests__aegis_api_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/build__aegis_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/build__aegis_api_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/build__aegis_core_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/build__aegis_react_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/watch__aegis_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/watch__aegis_api_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/watch__aegis_core_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/watch__aegis_react_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/aegis/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jujulego/aegis",
"version": "1.0.0-rc.2",
"version": "1.0.0-rc.3",
"license": "MIT",
"author": "Julien Capellari <julien.capellari@google.com>",
"repository": {
Expand Down Expand Up @@ -35,7 +35,7 @@
"regenerator-runtime": "^0.13.0"
},
"dependencies": {
"@jujulego/aegis-core": "^1.0.0-rc.1"
"@jujulego/aegis-core": "^1.0.0-rc.2"
},
"devDependencies": {
"@jujulego/flow": "1.1.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/aegis/src/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ export function $item<D, I extends AegisId>(entity: Entity<D>, arg1: I | Query<D
};

// Events
arg1.subscribe('update.failed', (state, mtd) => {
events.emit('query.failed', state, { source: mtd.source });
arg1.subscribe('status.failed', (state, mtd) => {
events.emit('status.failed', state, { source: mtd.source });
});

arg1.subscribe('update.completed', ({ result }, mtd) => {
arg1.subscribe('status.completed', ({ result }, mtd) => {
const id = entity.storeItem(result);
const $item = entity.item(id);

Expand All @@ -90,11 +90,11 @@ export function $item<D, I extends AegisId>(entity: Entity<D>, arg1: I | Query<D
events.emit(mtd.type, data, { source: mtd.source });
});

$item.subscribe('query', (data, mtd) => {
$item.subscribe('status', (data, mtd) => {
events.emit(mtd.type, data, { source: mtd.source });
});

events.emit('query.completed', { status: 'completed', result: result }, { source: mtd.source });
events.emit('status.completed', { status: 'completed', result: result }, { source: mtd.source });
});

return item;
Expand Down
2 changes: 1 addition & 1 deletion packages/aegis/src/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function $mutation<D, I extends AegisId>(entity: Entity<D>, query: Query<
};

if (!id) {
(query as Query<D>).subscribe('update.completed', (data) => {
(query as Query<D>).subscribe('status.completed', (data) => {
Object.assign(mutation, {
$id: JSON.parse(entity.storeItem(data.result))
});
Expand Down
48 changes: 24 additions & 24 deletions packages/aegis/tests/item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ describe('$item', () => {
expect(item.data).toEqual({ id: 'test', success: false });
});

it('should emit query manager events (query.pending)', () => {
it('should emit query manager events (status.pending)', () => {
const item = $item(entity, query);

query.complete({ id: 'test', success: true });

// Register listener
const spy = jest.fn();
item.subscribe('query.pending', spy);
item.subscribe('status.pending', spy);

// Emit event
item.$item?.refresh(() => new Query(), 'replace');
Expand All @@ -114,15 +114,15 @@ describe('$item', () => {
status: 'pending'
},
{
type: 'query.pending',
type: 'status.pending',
source: item.$item?.manager,
}
);

expect(item.isLoading).toBe(true);
});

it('should emit query manager events (query.completed)', () => {
it('should emit query manager events (status.completed)', () => {
const item = $item(entity, query);
query.complete({ id: 'test', success: true });

Expand All @@ -132,7 +132,7 @@ describe('$item', () => {

// Register listener
const spy = jest.fn();
item.subscribe('query.completed', spy);
item.subscribe('status.completed', spy);

// Emit event
q2.complete({ id: 'test', success: false });
Expand All @@ -143,15 +143,15 @@ describe('$item', () => {
result: { id: 'test', success: false }
},
{
type: 'query.completed',
type: 'status.completed',
source: q2,
}
);

expect(item.isLoading).toBe(false);
});

it('should emit query manager events (query.failed)', () => {
it('should emit query manager events (status.failed)', () => {
const item = $item(entity, query);
query.complete({ id: 'test', success: true });

Expand All @@ -161,7 +161,7 @@ describe('$item', () => {

// Register listener
const spy = jest.fn();
item.subscribe('query.failed', spy);
item.subscribe('status.failed', spy);

// Emit event
q2.fail(new Error('Failed !'));
Expand All @@ -172,23 +172,23 @@ describe('$item', () => {
error: new Error('Failed !')
},
{
type: 'query.failed',
type: 'status.failed',
source: q2,
}
);

expect(item.isLoading).toBe(false);
});

it('should emit query events (query.completed)', () => {
it('should emit query events (status.completed)', () => {
const item = $item(entity, query);

expect(item.$entity).toBe(entity);
expect(item.isLoading).toBe(true);

// Register listener
const spy = jest.fn();
item.subscribe('query.completed', spy);
item.subscribe('status.completed', spy);

// Emit event
query.complete({ id: 'test', success: true });
Expand All @@ -199,23 +199,23 @@ describe('$item', () => {
result: { id: 'test', success: true }
},
{
type: 'query.completed',
type: 'status.completed',
source: query,
}
);

expect(item.isLoading).toBe(false);
});

it('should emit query events (query.failed)', () => {
it('should emit query events (status.failed)', () => {
const item = $item(entity, query);

expect(item.$entity).toBe(entity);
expect(item.isLoading).toBe(true);

// Register listener
const spy = jest.fn();
item.subscribe('query.failed', spy);
item.subscribe('status.failed', spy);

// Emit event
query.fail(new Error('Failed !'));
Expand All @@ -226,7 +226,7 @@ describe('$item', () => {
error: new Error('Failed !')
},
{
type: 'query.failed',
type: 'status.failed',
source: query,
}
);
Expand Down Expand Up @@ -323,12 +323,12 @@ describe('$item', () => {
expect(item.data).toEqual({ id: 'test', success: false });
});

it('should emit query manager events (query.pending)', () => {
it('should emit query manager events (status.pending)', () => {
const item = $item(entity, 'test');

// Register listener
const spy = jest.fn();
item.subscribe('query.pending', spy);
item.subscribe('status.pending', spy);

// Emit event
item.$item.refresh(() => new Query(), 'replace');
Expand All @@ -338,15 +338,15 @@ describe('$item', () => {
status: 'pending'
},
{
type: 'query.pending',
type: 'status.pending',
source: item.$item.manager,
}
);

expect(item.isLoading).toBe(true);
});

it('should emit query manager events (query.completed)', () => {
it('should emit query manager events (status.completed)', () => {
const item = $item(entity, 'test');

// Refresh query
Expand All @@ -355,7 +355,7 @@ describe('$item', () => {

// Register listener
const spy = jest.fn();
item.subscribe('query.completed', spy);
item.subscribe('status.completed', spy);

// Emit event
query.complete({ id: 'test', success: false });
Expand All @@ -366,15 +366,15 @@ describe('$item', () => {
result: { id: 'test', success: false }
},
{
type: 'query.completed',
type: 'status.completed',
source: query,
}
);

expect(item.isLoading).toBe(false);
});

it('should emit query manager events (query.failed)', () => {
it('should emit query manager events (status.failed)', () => {
const item = $item(entity, 'test');

// Refresh query
Expand All @@ -383,7 +383,7 @@ describe('$item', () => {

// Register listener
const spy = jest.fn();
item.subscribe('query.failed', spy);
item.subscribe('status.failed', spy);

// Emit event
query.fail(new Error('Failed !'));
Expand All @@ -394,7 +394,7 @@ describe('$item', () => {
error: new Error('Failed !')
},
{
type: 'query.failed',
type: 'status.failed',
source: query,
}
);
Expand Down
Loading