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

Weird behaviour on toJSON method #24

Closed
danielbdias opened this issue May 28, 2017 · 5 comments
Closed

Weird behaviour on toJSON method #24

danielbdias opened this issue May 28, 2017 · 5 comments
Labels

Comments

@danielbdias
Copy link

When you fill a child element with an invalid value toJSON method acts in a weird way. The parent toJSON returns the old child element and the toJSON of the child element returns the child element in the invalid state.

For example, given the schema:

class MyEntity extends Speck {
  static SCHEMA = {
    field: PropTypes.string,
    anotherField: PropTypes.string
  }
}

class FatherEntity extends Speck {
  static SCHEMA = {
    child: PropTypes.instanceOf(MyEntity)
  }
}

And the variables setup:

const a = new FatherEntity({ child: { field: 'value' } })
a.child = { field: 'invalid entity', anotherField: 'yet a invalid entity' }

The toJSON method have this behaviour:

//prints { child: { field: 'value' } }
console.log(a.toJSON()) 
//prints { field: 'invalid entity', anotherField: 'yet a invalid entity' }
console.log(a.child.toJSON()) 
@guisouza
Copy link
Contributor

try with :

class FatherEntity extends Speck {
  static SCHEMA = {
    child: {
      validator: PropTypes.instanceOf(MyEntity),
      type: MyEntity
    }
  }
}

@guisouza guisouza added the bug label May 28, 2017
@guisouza
Copy link
Contributor

@danielbdias should we close this issue ?

@danielbdias
Copy link
Author

Please, @guisouza not yet, can you wait two more days? I will do one more test to simulate this error (and another to use your solution).
Thanks !

@guisouza
Copy link
Contributor

guisouza commented Jul 2, 2017

No problem, take your time ..

@danielbdias
Copy link
Author

I can't simulate this error anymore. For now I think that is better to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants