Skip to content

feat(pinia-orm): add life-cycle-hooks#91

Merged
CodeDredd merged 5 commits intomasterfrom
life-cycle
Jul 18, 2022
Merged

feat(pinia-orm): add life-cycle-hooks#91
CodeDredd merged 5 commits intomasterfrom
life-cycle

Conversation

@CodeDredd
Copy link
Copy Markdown
Owner

@CodeDredd CodeDredd commented Jul 15, 2022

Thoughts

Adding local & global life cycle hooks like retrieved, creating, created, updating, updated, saving, saved, deleting, deleted.

ToDos

  • Creating
  • Created
  • Updating
  • Updated
  • Deleting
  • Deleted
  • Retrieved
  • Saving
  • Saved
  • Docs

Examples

    class User extends Model {
      static entity = 'users'

      @Num(0) id!: number
      @Str('') name!: string
      @Num(0) age!: number

      static updating(model: Model) {
        model.name = 'John'
      }
    }

@CodeDredd CodeDredd added the enhancement New feature or request label Jul 15, 2022
@CodeDredd CodeDredd self-assigned this Jul 15, 2022
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jul 15, 2022

Codecov Report

Merging #91 (20523c0) into master (0a7b6b9) will decrease coverage by 0.07%.
The diff coverage is 96.96%.

@@            Coverage Diff             @@
##           master      #91      +/-   ##
==========================================
- Coverage   99.59%   99.51%   -0.08%     
==========================================
  Files          51       51              
  Lines        4181     4329     +148     
  Branches      317      338      +21     
==========================================
+ Hits         4164     4308     +144     
- Misses         17       21       +4     
Impacted Files Coverage Δ
packages/pinia-orm/src/query/Query.ts 99.43% <94.11%> (-0.57%) ⬇️
packages/pinia-orm/src/model/Model.ts 100.00% <100.00%> (ø)
packages/pinia-orm/src/data/Data.ts 100.00% <0.00%> (ø)
packages/pinia-orm/src/modules/State.ts 100.00% <0.00%> (ø)
packages/pinia-orm/src/query/Options.ts 100.00% <0.00%> (ø)
packages/pinia-orm/src/modules/RootState.ts 100.00% <0.00%> (ø)
...ckages/pinia-orm/src/model/decorators/Contracts.ts 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a7b6b9...20523c0. Read the comment docs.

@CodeDredd CodeDredd merged commit ca67576 into master Jul 18, 2022
@CodeDredd CodeDredd deleted the life-cycle branch July 18, 2022 10:06
@garma83
Copy link
Copy Markdown

garma83 commented Aug 3, 2022

@CodeDredd would it be an idea to add find hooks as well? would make sense to complete CRUD support

@CodeDredd
Copy link
Copy Markdown
Owner Author

@erikpols yes it would make sense. As you can see, initially I intended to have retrieve. But I reliesed that it's a bit more difficult. That's why I dropped it first.
The problem right now is that the get method is used also internally. So I would get many retrieved hooks.

But still... your right. I try to find a solution. Not just for find.

@garma83
Copy link
Copy Markdown

garma83 commented Aug 4, 2022

gotcha ty!

There are a few others too, for bulk updates for example. This is useful if you want to use the hooks for axios calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants