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(pinia-orm): add mutators #84

Merged
merged 10 commits into from
Jul 13, 2022
Merged

feat(pinia-orm): add mutators #84

merged 10 commits into from
Jul 13, 2022

Conversation

CodeDredd
Copy link
Owner

@CodeDredd CodeDredd commented Jul 12, 2022

Thoughts

Mutators are coming back. In a better way.
There will be now also the possibilty to have a set mutator. The one big differnce is that you still can't put mutators in the field configuration.

Add wish vuex-orm/vuex-orm-next#114 and fix issue vuex-orm/vuex-orm#524, issue vuex-orm/vuex-orm#744

Checklist

  • Docs
  • Tests
  • Decorator
  • Decorator Tests
  • Working setter & getter

Examples

Getter & Setter

    class User extends Model {
      static entity = 'users'

      @Attr(0) id!: number
      @Attr('') name!: string

      static mutators() {
        return {
          name: {
            get: (value: any) => value.toUpperCase(),
            set: (value: any) => value.toLowerCase(),
          },
        }
      }

Function get

    class User extends Model {
      static entity = 'users'

      @Attr('') name!: string

      static mutators() {
        return {
          name(value: any) {
            return value.toUpperCase()
          },
        }
      }
    }

Decorator

    class User extends Model {
      static entity = 'users'

      @Mutate((value: any) => value.toUpperCase())
      @Attr('')
        name!: string
    }

Feedback welcome

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

codecov-commenter commented Jul 12, 2022

Codecov Report

Merging #84 (18e03fe) into master (52175e2) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 18e03fe differs from pull request most recent head da5c41c. Consider uploading reports for the commit da5c41c to get more accurate results

@@           Coverage Diff           @@
##           master      #84   +/-   ##
=======================================
  Coverage   99.58%   99.59%           
=======================================
  Files          50       51    +1     
  Lines        4112     4186   +74     
  Branches      308      317    +9     
=======================================
+ Hits         4095     4169   +74     
  Misses         17       17           
Impacted Files Coverage Δ
packages/pinia-orm/src/model/Model.ts 100.00% <100.00%> (ø)
packages/pinia-orm/src/model/decorators/Mutate.ts 100.00% <100.00%> (ø)
packages/pinia-orm/src/query/Query.ts 100.00% <100.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 52175e2...da5c41c. Read the comment docs.

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.

2 participants