Open Side Menu Go to the Top

07-01-2019 , 11:16 AM
OK so I've been screwing around with react-promise which, uh, promises to solve this problem. And it does seem to. But now I have a new one. Below is my component, it "works" but it goes in an endless loop, constantly re-rendering itself, and I have no idea why.

Code:
const PCBRender = (props) => {
  const updateImage = async () => {
    const fw = props.store.get('frameworks')
    const data = await fw.PCBApi.render({
      project_key: props.project_key,
      username: props.username,
      side: props.side,
    })
    return 'data:image/jpeg;base64,' + data
  }

  const {value, loading} = usePromise(updateImage())
  if (loading) return null
  return <div>{value}</div>
}
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
07-01-2019 , 12:33 PM
You definitely still need a check somewhere to see if the props.project_key has changed. That's why generally you store state in a component that's a parent to both your display component and your user-interactive component.

I don't know all the ways to make react work but I know this way works for us.

1) User initiates project change in let's say ChangeProject component:

Code:
class ChangeProject extends React.Component {
  render() <ChangeProjectWidget onChange="this.props.updateProject" />
}
2) ChangeProject component calls props.updateProject(newProjectKey) - which was passed to it by its parent (or grandparent, etc.) - ProjectPage component:

Code:
class ProjectPage extends React.Component {
  const updateProject = async () => {
    const fw = props.store.get('frameworks')
    const data = await fw.PCBApi.render({
      project_key: props.project_key,
      username: props.username,
      side: props.side,
    })
    this.setState('projectImage', 'data:image/jpeg;base64,' + data);
  }
  
  render() 
    <div>
       <ChangeProject updateProject="this.updateProject" />
       <PCBRender projectImage={this.state.projectImage} />
    </div>
}
3) updateProject in ProjectPage component calls await fw.PCBApi.render(...) then when the result comes back changes its state to automatically update PCBRender component:

Code:
class PCBRender extends React.Component {
  render() {
    return 
      {!this.props.projectImage && <div>loading...</div>}
      {this.props.projectImage && <div><img src={this.props.projectImage}/></div>}
  }
}
Or something like this.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 12:45 PM
I’m curious to hear how you guys do onsite interviews?

Our company does two system design and two coding rounds and last round with the hiring manager. Each round is rated between 1 to 4.

I think the system design is excessive especially when we interview candidates with less than 2 years experience.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 01:10 PM
Quote:
Originally Posted by suzzer99
You definitely still need a check somewhere to see if the props.project_key has changed. That's why generally you store state in a component that's a parent to both your display component and your user-interactive component.
Maybe this is just preference but to me it seems here like you've added a dependency between 2 components that don't require it, to avoid using the componentDidUpdate. It doesn't seem like a net gain to me?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 01:28 PM
Actually, I didn't need the componentDidUpdate anyway - I was wrong about why it was there. I've removed it.

ETA: this is the whole thing now

Code:
class PCBRender extends React.Component {
  loading_color = '#555888'
  
  constructor(props) {
    super(props);
    this.state = {
      img: '',
    };
  };

  componentDidMount() {
    this.updateImage()
  }

  async updateImage() {
    const fw = this.props.store.get('frameworks')
    const data = await fw.PCBApi.render({
      project_key: this.props.project_key,
      username: this.props.username,
      side: this.props.side,
    })
    this.setState({img: 'data:image/jpeg;base64,' + data})
  }

  render() {
    let { classes } = this.props
    return (!this.state.img.length)
      ? <div className={classes.loadingDiv}><ReactLoading className={classes.loading} type={'spinningBubbles'} color={this.loading_color} height={50} width={50} /></div>
      : <img src={this.state.img}/>
  }
}

Last edited by RustyBrooks; 07-01-2019 at 01:50 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 01:54 PM
Quote:
Originally Posted by RustyBrooks
Maybe this is just preference but to me it seems here like you've added a dependency between 2 components that don't require it, to avoid using the componentDidUpdate. It doesn't seem like a net gain to me?
You already have a dependency with your user-interaction component somewhere - unless you snipped it out of your PCBRender component.

I believe in general the react way is to make tiny components that just do one thing - then have a parent component handle the orchestration between them. IE - a switch component just cares about firing off a method when the user switches projects, then a render component only cares about rendering the image tag, or loading message when it gets new props from its parent.

So in this case your parent doesn't need to be the whole page - it could just be a dedicated parent component to those two - and you could think the package of 3 as a single component basically.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 02:14 PM
Quote:
Originally Posted by suzzer99
You already have a dependency with your user-interaction component somewhere - unless you snipped it out of your PCBRender component.
I think I was wrong about that. I don't remember now why I had the componentDidUpdate, or why I needed to check for project_key = null, I don't need either of those now.

PCBRender's who job is to take a project_key in and deliver the related image. With a small change you should even be able to route straight to it which would theoretically let people embed them in other pages and stuff (you'd either need to auth or only use public projects)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 02:14 PM
Quote:
Originally Posted by RustyBrooks
Actually, I didn't need the componentDidUpdate anyway - I was wrong about why it was there. I've removed it.

ETA: this is the whole thing now

Code:
class PCBRender extends React.Component {
  loading_color = '#555888'
  
  constructor(props) {
    super(props);
    this.state = {
      img: '',
    };
  };

  componentDidMount() {
    this.updateImage()
  }

  async updateImage() {
    const fw = this.props.store.get('frameworks')
    const data = await fw.PCBApi.render({
      project_key: this.props.project_key,
      username: this.props.username,
      side: this.props.side,
    })
    this.setState({img: 'data:image/jpeg;base64,' + data})
  }

  render() {
    let { classes } = this.props
    return (!this.state.img.length)
      ? <div className={classes.loadingDiv}><ReactLoading className={classes.loading} type={'spinningBubbles'} color={this.loading_color} height={50} width={50} /></div>
      : <img src={this.state.img}/>
  }
}
I believe the only way this can work for updates is if you're completely wiping out and re-rendering the component from its parent.

The more react-y way is to not wipe out the component, just update whatever is passed to it as props. That wouldn't work with this setup because updateImage() will never be called again after the first render.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 02:16 PM
Quote:
Originally Posted by Barrin6
I’m curious to hear how you guys do onsite interviews?

Our company does two system design and two coding rounds and last round with the hiring manager. Each round is rated between 1 to 4.

I think the system design is excessive especially when we interview candidates with less than 2 years experience.
That sounds brutal but probably standard

We have a coding project first. Then we have 2 tech on site sessions, one is a live code review with 3 devs, the second is one algo coding question and 1 domain design question (we have 4 specific questions and we ask 2 of them)

Then it's 30 mins with some leadership and 30 mins with hr. 3 hours total. Nothing too brutal
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 02:19 PM
Quote:
Originally Posted by suzzer99
I believe the only way this can work for updates is if you're completely wiping out and re-rendering the component from its parent.

The more react-y way is to not wipe out the component, just update whatever is passed to it as props. That wouldn't work with this setup because updateImage() will never be called again after the first render.
Then I probably do need the componentDidUpdate. This project has been changing really rapidly, so for example I removed the project switching stuff yesterday temporarily. Anyway, I'll get it worked out.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 02:26 PM
And actually what I'm struggling with now is some dumb geometry rendering stuff. And example of the project I'm working on is this:
http://cadcam.rustybrooks.com/projects/rbrooks/test
which renders PCB images from Gerber files. You can actually select which layers you want to see but that's all disabled at the moment.

These are PNGs and they're fine for getting an idea of what the thing looks like, but when it comes to turning this into the CNC instructions for actually making the PCB, I need to work with vectors. And it's simpler in that case to display the PCB as an SVG. But I keep running into a rendering issue.

The short explanation is that due to the way the geometry library stores polygons, there are cases where you have sort of a polygon inside a polygon inside a polygon. The inner polygon only gets rendered correctly if it's *after* the outer polygon(s) in the SVG. Here's an example of that (it's pretty slow)


So the sort of medium-pink shade that most of the image is, that's the color all the copper traces should be, and everything else should be white. I have everything with alpha=0.5 so you can see the stuff that's "behind" other pieces, they show as either lighter or darker depending on whether they represent copper or empty space.

It doesn't affect the CAM parts because the geometry is all *there*, just the rendering. I really am not looking forward to writing some kind of dumb z-sorter, which is just going to make the whole thing a lot slower.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 03:44 PM
Quote:
Originally Posted by suzzer99
What are func tests to you? Is that like integration tests?
Yep, backend is mocked out by a fake server and tests just check that UI does what it's supposed to do.

Quote:
Originally Posted by Victor
Seems very fast for e2e. What frameworks for testing and backend?
E2E tests use Java, Cucumber, Selenide. Backend is mostly written in Java (or in some other JVM language).

Quote:
Originally Posted by RustyBrooks
We've had e2e tests for like 3 years, as far as I know they've never caught or prevented a single bug.
Dunno. Our tests catch quite a lot of stuff. For example screenshot tests (those compare feature branch with master) catch CSS misalignments quite often.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 04:36 PM
Hey guys,

In a bit of a pinch here. Had some surprise turnover and need to learn node.js in about a week. Don't need mastery of it, but just assume I don't know anything about anything about node, and have a little bit of vanilla JS experience. Where can I start?

For background we have a wrapper around our C API's for node. So I don't really need to know a ton about how node works or to develop in it - just enough to get by for now and maybe do some light debugging or code reviews.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 05:17 PM
Check out udemy - I got a ton out of the AWS courses I took.

The main concepts over and above vanilla JS you need to know imo are: asynchronous coding, closures and middleware (or pipes, etc.)

Try to do everything you can with async/await - even if the older examples you find use callbacks or expanded promises (async/await is just terse promises, and promises are just standardized callbacks).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 09:06 PM
suzzer's big tip o' the day: When you cross stuff off your TODO list, don't delete it - move it to a DONE section. That way when you have to write a big PPT about everything you did, or when you have to do your mid-year/end-of-year reviews - you'll remember.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 09:24 PM
At the end of every month I jot down what I did (or what I can say I did) so I can use it in our "OKRs".
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 10:39 PM
I just look at git commits and closed JIRA tickets more or less.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 11:06 PM
Anyone use Auth0? If so how do you feel about the dev experience and the pricing models?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 11:18 PM
We did with the startup I worked for. It worked pretty well - seems like their support was ok. I didn't look into pricing.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-01-2019 , 11:25 PM
Quote:
Originally Posted by PJo336
Anyone use Auth0? If so how do you feel about the dev experience and the pricing models?
I have used it. I would not say I'm a fan, but my experience is a few years out of date.

It looked to me like they had 2 different databases, and different API calls would hit different databases. I suspect that one of them was elastic search. So for example you could create a user and then try to log them in and it would fail. Try to fetch their profile and it would fail. Wait a minute and try again and it would work.

Similarly I would sometimes delete users via some API call and then go to their web interface, users are still there. We had some functional tests that would create users, wait wait wait wait wait, do something, delete users. Users would often seem to delete OK, as in you couldn't log in with them or query them, but then you'd go to the web interface and there's 200 test users sitting there.

Sometimes we have to contact them and get them to true up one database from the other (or at least that's what I assume they were doing, we'd complain and they'd do something and it would become consistent again)

Anyway integrating with it was not that complicated although I found their data model a little confusing. We were definitely using it the wrong way when we started. There are a ton of settings also and it can be hard to figure out which ones you want and getting it all set up correctly.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-02-2019 , 10:33 AM
I use a personal trello board for my TODO list and its actually ended up working pretty well. I'd tried a bunch of things before but always kept falling back to a textedit doc + email.

So I can just archive tasks I've done and review them if I ever really care.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-02-2019 , 10:37 AM
I use handwritten notes in 120 page wide rule notebooks. I write down a daily to do and weekly ones and then throughout the day kinda write down everything I have been doing, meeting notes, random crap in the margins, notes of conversations I’ve had that may be important to remember - I think I have about 900 pages so far lol.

Sticky notes for remembering really specific things i know i’ll come back to. You’d think they’d be hard to reference back to but since I have them organized by date, I can just look up an email or something, want to know more, grab the date and go to that date in my notebooks and find the day pretty quickly.

The only thing that sucks is sometimes when I get really into a problem i stop writing for a day or two. But thats really only when i’m developing.

Coworkers obv think it’s super weird but a major part of my job is just knowing everything that’s going on and you cant possibly keep it all in your head at once.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-02-2019 , 10:41 AM
Node is pretty cool fyi. I love how easy it is to deploy a server just right out of the box. It’s almost making me rethink my passionate hatred of JS.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-02-2019 , 10:46 AM
Quote:
Originally Posted by jjshabado
I use a personal trello board for my TODO list and its actually ended up working pretty well. I'd tried a bunch of things before but always kept falling back to a textedit doc + email.

So I can just archive tasks I've done and review them if I ever really care.
Haha same. I switched to using a simple kanban board on trello. It is very lightweight, cross platform, and is working better than my older GTD based system.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-02-2019 , 11:04 AM
Quote:
Originally Posted by jmakin
I use handwritten notes in 120 page wide rule notebooks. I write down a daily to do and weekly ones and then throughout the day kinda write down everything I have been doing, meeting notes, random crap in the margins, notes of conversations I’ve had that may be important to remember - I think I have about 900 pages so far lol.

Sticky notes for remembering really specific things i know i’ll come back to. You’d think they’d be hard to reference back to but since I have them organized by date, I can just look up an email or something, want to know more, grab the date and go to that date in my notebooks and find the day pretty quickly.

The only thing that sucks is sometimes when I get really into a problem i stop writing for a day or two. But thats really only when i’m developing.

Coworkers obv think it’s super weird but a major part of my job is just knowing everything that’s going on and you cant possibly keep it all in your head at once.
You should try Trello. It makes all of this easy. I have lists for:

Today
Blocked [Things I need to do today/this week but that is blocked]
This Week
This Month
Month+1 [August]
Month+2 [September]
Later

Anytime I "get work" (email, slack message, meeting action, something I think up myself, etc.) that can't be done immediately it just gets put into the right list as a card with any relevant details.

Then every morning I review/update my today list and this week list. Every Monday I review/update my this week / this month list. Start of every month I review the other ones.

References to other material (PRs, emails, etc.) are always simple because they're on the card.

My email + textedit strategy generally worked well for short-term tasks, but worked really poorly for things I needed to do sometime in the next month or two.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m