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

Decorator support #8

Open
kristianmandrup opened this issue Jan 15, 2017 · 2 comments
Open

Decorator support #8

kristianmandrup opened this issue Jan 15, 2017 · 2 comments
Assignees

Comments

@kristianmandrup
Copy link

Allow for fields static method

http://aliolicode.com/2016/05/07/typescript-static-members/

https://github.com/xpepermint/vue-rawmodel/blob/master/src/models.ts#L29

public constructor (data: ReactiveModelRecipe = {}) {
    super(data);
    // ...
    let clazz = this.constructor;
    fields = fields || typeof clazz.fields === 'function' ? clazz.fields() : clazz.fields
    if (fields) this.defineFields(fields)
  }
import {ReactiveModel} from 'vue-rawmodel';

class User extends ReactiveModel {
  constructor (data = {}) {
    super(data); // initializing parent class
  }

  static fields() {
    return {
      name: {
        type: 'String', // setting type casting
        validate: [{
            validator: 'presence', // validator name
            message: 'is required' // validator error message
          }
        ]
      }
    };
  }
}

Equivalent to calling

  constructor (data = {}) {
    super(data); // initializing parent class
    this.defineField({
      // ...
    }
  }
@smolinari
Copy link

A note on the side: 😄

If "ReactiveModel" is a fitting name, it (or VueReactiveModel) is sexier than VueRawModel. 😉

Scott

@xpepermint xpepermint self-assigned this Jan 16, 2017
@xpepermint
Copy link
Owner

vue-class-component is an official companion library that allows you to declare components as native JavaScript classes, with a @component decorator.

Based on this quote from the official Vue.js documentation, I decided to add decorator support. Coming soon ...

@xpepermint xpepermint changed the title Allow fields static class method to be used as default for defineFields Decorator support Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants