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

[flow] Polymorphic classes #966

Closed
sslotsky opened this issue May 30, 2017 · 1 comment
Closed

[flow] Polymorphic classes #966

sslotsky opened this issue May 30, 2017 · 1 comment

Comments

@sslotsky
Copy link

I also posted this issue on the vim-flow repo, but since then I saw #592 here which presents the possibility that it needs to be fixed for this plugin.

Using generics/polymorphism with es6 classes seems to break syntax highlighting. Here's the contents of the file causing the issue:

// @flow

import { Component, Element } from 'react';
import { allDates } from './calendarData';
import range from './lib/range';

function selectedDate(value) {
  const date = (Date.parse(value) && new Date(value)) || new Date();
  date.setHours(0, 0, 0, 0);
  return date;
}

function startDate({ value }) {
  const date = selectedDate(value);

  return {
    month: date.getMonth() + 1,
    year: date.getFullYear()
  };
}

type Props = { value: string };
type State = { month: number, year: number };

export default class SlimProto<T> extends Component<void, Props & T, State> {
  state = startDate(this.props);

  componentWillReceiveProps(nextProps: Props) {
    if (this.props.value !== nextProps.value) {
      this.setState(startDate(nextProps));
    }
  }

  props: Props & T;

  previousYear = () => {
    this.setState(({ year }) => ({ year: year - 1 }));
  };

  nextYear = () => {
    this.setState(({ year }) => ({ year: year + 1 }));
  };

  previousMonth = () => {
    this.setState(({ month, year }) => {
      if (month === 1) {
        return { month: 12, year: year - 1 };
      }
      return { month: month - 1, year };
    });
  };

  nextMonth = () => {
    this.setState(({ month, year }) => {
      if (month === 12) {
        return { month: 1, year: year + 1 };
      }
      return { month: month + 1, year };
    });
  };

  selected() {
    return selectedDate(this.props.value);
  }

  rows() {
    const { month, year } = this.state;
    const { buckets } = allDates(month, year);
    const rowCount = Math.ceil(buckets.length / 7);

    return range(1, rowCount).map((n) => {
      const start = 7 * (n - 1);

      return {
        columns: buckets.slice(start, start + 7)
      };
    });
  }

  render(): ?Element<*> {
    return null;
  }
}

How it appears in my editor is inconsistent. The screenshot that I left on the vim-flow repo is what it looked like yesterday. Today it appears as below. Besides the obvious red highlighted bracket, the render method also normally appears in blue.

image

amadeus added a commit that referenced this issue Jun 26, 2017
Fixes #901
Fixes #966
Fixes #983
Fixes #891
Fixes #885
Fixes #845
Fixes #792
Fixes #723
Fixes #567

This is all a bit hairy, but I think I put a big dent in a lot of the
common flow problems that have been reported. I want to sit on these
changes for a few days though to make sure I didn't cause a serious
regression.
@amadeus
Copy link
Collaborator

amadeus commented Jun 26, 2017

I've recently created a branch with some flow fixes, if you could do me a solid and test it: #991

amadeus added a commit that referenced this issue Jun 26, 2017
Fixes #901
Fixes #966
Fixes #983
Fixes #891
Fixes #885
Fixes #845
Fixes #792
Fixes #723
Fixes #567

This is all a bit hairy, but I think I put a big dent in a lot of the
common flow problems that have been reported. I want to sit on these
changes for a few days though to make sure I didn't cause a serious
regression.
amadeus added a commit that referenced this issue Jul 9, 2017
Fixes #901
Fixes #966
Fixes #983
Fixes #891
Fixes #885
Fixes #845
Fixes #792
Fixes #723
Fixes #567

This is all a bit hairy, but I think I put a big dent in a lot of the
common flow problems that have been reported. I want to sit on these
changes for a few days though to make sure I didn't cause a serious
regression.
amadeus added a commit that referenced this issue Jul 12, 2017
Fixes #901
Fixes #966
Fixes #983
Fixes #891
Fixes #885
Fixes #845
Fixes #792
Fixes #723
Fixes #567

This is all a bit hairy, but I think I put a big dent in a lot of the
common flow problems that have been reported. I want to sit on these
changes for a few days though to make sure I didn't cause a serious
regression.
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

2 participants