Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Documentation tool: parse(path: t.String) => JSON module #24

Closed
gcanti opened this issue Jan 16, 2016 · 0 comments
Closed

Documentation tool: parse(path: t.String) => JSON module #24

gcanti opened this issue Jan 16, 2016 · 0 comments
Milestone

Comments

@gcanti
Copy link
Owner

gcanti commented Jan 16, 2016

Source

import React from 'react'
import { props, t } from 'tcomb-react'
import User from './User'

/**
 * Component description here
 * name and surname must be both nil or both specified
 * @param name - name description
 * @param surname - surname description
 */

const Props = t.refinement(t.struct({
  name: t.maybe(User.meta.props.name),
  surname: t.maybe(User.meta.props.surname)
}), (x) => t.Nil.is(x.name) === t.Nil.is(x.surname))

@props(Props)
export default class Card extends React.Component {

  static defaultProps = {
    name: 'Giulio',
    surname: 'Canti'
  }

  render() {
    return (
      <div>
        <p>{this.props.name}</p>
        <p>{this.props.surname}</p>
      </div>
    )
  }
}

Usage

var parse = require('tcomb-react/lib/parse');
var json = parse('../components/Card.js');
console.log(JSON.stringify(json, null, 2));

Output

{
  "name": "Card",
  "description": "Component description here\nname and surname must be both nil or both specified",
  "props": {
    "name": {
      "kind": "irreducible",
      "name": "String",
      "required": false,
      "defaultValue": "Giulio",
      "description": "name description"
    },
    "surname": {
      "kind": "irreducible",
      "name": "String",
      "required": false,
      "defaultValue": "Canti",
      "description": "surname description"
    }
  }
}
@gcanti gcanti added this to the 0.8.12 milestone Jan 16, 2016
gcanti added a commit that referenced this issue Jan 16, 2016
gcanti added a commit that referenced this issue Jan 16, 2016
gcanti added a commit that referenced this issue Jan 17, 2016
gcanti added a commit that referenced this issue Jan 17, 2016
gcanti added a commit that referenced this issue Jan 23, 2016
@gcanti gcanti closed this as completed in 3b5c8f2 Jan 23, 2016
gcanti added a commit that referenced this issue Jan 23, 2016
Documentation tools, fix #24, fix #25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant