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

feat: Separate update event into the update, soft remove and recover events #8403

Merged
merged 1 commit into from Feb 15, 2022
Merged

Conversation

spotykatch
Copy link
Contributor

@spotykatch spotykatch commented Nov 23, 2021

Closes: #8398

BREAKING CHANGE: update listeners and subscriber no longer triggered by soft-remove and recover

Fixes: #6179

Description of change

Separate update event into the update, soft remove and recover events

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change [ Need help with Chinese docs ]
  • The new commits follow conventions explained in CONTRIBUTING.md

@spotykatch spotykatch changed the title 2 Separate update event into the update, soft remove and restore events Nov 23, 2021
@spotykatch
Copy link
Contributor Author

spotykatch commented Nov 23, 2021

Don't really get how listeners are registered. I get this output.

BEFORE_UPDATE_LISTENER_CALL
BEFORE_UPDATE_SUBSCRIBER_CALL
AFTER_UPDATE_LISTENER_CALL
AFTER_UPDATE_SUBSCRIBER_CALL
0 // <-- metadata.updateListeners.length
BEFORE_SOFT_REMOVE_SUBSCRIBER_CALL
AFTER_SOFT_REMOVE_SUBSCRIBER_CALL
BEFORE_RECOVER_SUBSCRIBER_CALL
AFTER_RECOVER_SUBSCRIBER_CALL

Any help? Where listeners are registered?

@spotykatch
Copy link
Contributor Author

spotykatch commented Nov 23, 2021

callListethis.expressionMap.callListenersners is false for some reason oO
Ok. found.

@spotykatch
Copy link
Contributor Author

spotykatch commented Nov 24, 2021

LOL. Did not expect checks will be passed so soon) Maybe there should be more checks?
I'll push docs changes. And I think I will need some help here because my English is not good enough to write docs I guess.
Also, I need some guidance to make sure users understand, that update events are no longer triggered by soft remove and recover.

@spotykatch spotykatch marked this pull request as ready for review November 24, 2021 06:33
@spotykatch
Copy link
Contributor Author

spotykatch commented Nov 24, 2021

Sorry, can you, please, change it back to draft.

@spotykatch spotykatch changed the title Separate update event into the update, soft remove and restore events Separate update event into the update, soft remove and recover events Nov 26, 2021
@spotykatch
Copy link
Contributor Author

In Chinese documentation, I only changed English words 😶‍🌫️

@spotykatch spotykatch marked this pull request as draft November 26, 2021 04:37
@spotykatch
Copy link
Contributor Author

spotykatch commented Nov 26, 2021

Should there be tests for relations?
I'll change it ready for review to get comments. It's not ready still.

@spotykatch spotykatch marked this pull request as ready for review November 26, 2021 12:40
@spotykatch spotykatch changed the title Separate update event into the update, soft remove and recover events feat: Separate update event into the update, soft remove and recover events Dec 7, 2021
@@ -700,6 +706,82 @@ export class Post {

Learn more about [listeners](listeners-and-subscribers.md).

#### `@BeforeSoftRemove`

You can define a method with any name in the entity and mark it with `@BeforeRemove`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @BeforeRemove should be @BeforeSoftRemove here

@Entity()
export class Post {

@BeforeRemove()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue


#### `@AfterSoftRemove`

You can define a method with any name in the entity and mark it with `@AfterRemove`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue

@Entity()
export class Post {

@AfterRemove()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue

@Entity()
export class Post {

@BeforeRemove()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue


#### `@AfterRecover`

You can define a method with any name in the entity and mark it with `@AfterRemove`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue

@Entity()
export class Post {

@AfterRemove()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue

* [`@BeforeSoftRemove`](#beforeremove)
* [`@AfterSoftRemove`](#afterremove)
* [`@BeforeRecover`](#beforeremove)
* [`@AfterRecover`](#afterremove)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect links all above ^

@@ -89,6 +94,7 @@ export class Post {

You can define a method with any name in the entity and mark it with `@AfterUpdate`
and TypeORM will call it after an existing entity is updated using repository/manager `save`.
> :warning: **@AfterUpdate is no longer triggered by `softRemove` and `recover`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need these warnings above, just remove the all

@Entity()
export class Post {

@BeforeRemove()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue

@Entity()
export class Post {

@BeforeRemove()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue

#### `@AfterSoftRemove`

You can define a method with any name in the entity and mark it with `@AfterRemove`
and TypeORM will call it after the entity is soft removed using repository/manager `remove`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using softRemove ?

#### `@BeforeSoftRemove`

You can define a method with any name in the entity and mark it with `@BeforeRemove`
and TypeORM will call it before a entity is soft removed using repository/manager `remove`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using softRemove ?

* [`@BeforeSoftRemove`](#beforeremove)
* [`@AfterSoftRemove`](#afterremove)
* [`@BeforeRecover`](#beforeremove)
* [`@AfterRecover`](#afterremove)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

links are broken ^

* [`@BeforeSoftRemove`](#beforeremove)
* [`@AfterSoftRemove`](#afterremove)
* [`@BeforeRecover`](#beforeremove)
* [`@AfterRecover`](#afterremove)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

links are broken ^


### `@AfterSoftRemove`

你可以在实体中定义一个具有任何名称的方法,并使用`@ AfterSoftRemove`标记它,TypeORM 将在使用 repository/manager `softRemove`删除实体后调用它。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant space

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and missing spaces


### `@BeforeRecover`

你可以在实体中定义具有任何名称的方法,并使用`@BeforeRecover`标记它,并且 TypeORM 将在使用 repository/manager `recover`删除实体之前调用它。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and missing spaces


### `@AfterRecover`

你可以在实体中定义一个具有任何名称的方法,并使用`@ AfterRecover`标记它,TypeORM 将在使用 repository/manager `recover`删除实体后调用它。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and missing spaces

if (this.expressionMap.queryType === "soft-delete")
await queryRunner.broadcaster.broadcast("BeforeSoftRemove", this.expressionMap.mainAlias!.metadata);
else if (this.expressionMap.queryType === "restore")
await queryRunner.broadcaster.broadcast("AfterSoftRemove", this.expressionMap.mainAlias!.metadata);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it should be BeforeRecover here?

@pleerock
Copy link
Member

Since this PR contains many small typos and copy-paste issues I recommend to go through the code once again (in case if I missing something) and make sure no issues left. Good job on a PR itself

@spotykatch
Copy link
Contributor Author

spotykatch commented Dec 21, 2021

del

@spotykatch spotykatch marked this pull request as draft December 21, 2021 17:24
@spotykatch spotykatch marked this pull request as ready for review December 21, 2021 17:35
@pleerock
Copy link
Member

@spotykatch were you able to fix the remaining issues before we can merge this one?

@spotykatch
Copy link
Contributor Author

Chinese docs are the only got left. I hope Chinese users will fix it themselves 😺

@pleerock
Copy link
Member

pleerock commented Feb 1, 2022

image

Closes: #8398

BREAKING CHANGE: update listeners and subscriber no longer triggered by soft-remove and recover
@pleerock pleerock merged commit 93383bd into typeorm:master Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants