This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import fetchData from "./fetchData"; | |
export default function permitList(props) { | |
const data = fetchData("https://data.cityofchicago.org/resource/ydr8-5enu.json?"); | |
return ( | |
<div> | |
<ul> | |
{data.map(el => ( | |
<li key={el.id}>{el.permit_type}</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fetchData.js | |
import { useState, useEffect } from "react"; | |
export default function fetchData(url) { | |
const [data, setData] = useState([]); | |
useEffect(() => { | |
fetch(url) | |
.then(response => response.json()) | |
.then(data => setData(data)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<DataFetcher | |
render={data => { | |
return ( | |
<div> | |
<ul> | |
{data.map(el => ( | |
<li key={el.id}>{el.title}</li> | |
))} | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
export default class DataFetcher extends Component { | |
state = { data: [] }; | |
componentDidMount() { | |
fetch("https://data.cityofchicago.org/resource/ydr8-5enu.json?") | |
.then(response => response.json()) | |
.then(data => | |
this.setState(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dataFetcher.js | |
import { useState, useEffect } from "react"; | |
export default function dataFetcher(url) { | |
const [data, setData] = useState([]); | |
useEffect(() => { | |
fetch(url) | |
.then(response => response.json()) | |
.then(data => setData(data)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# graffiti.rb | |
class Graffiti < ActiveRecord::Base | |
belongs_to :artist, class_name: "User" | |
has_many :uploads | |
has_many :comments | |
has_many :upvotes, as: :upvotable | |
end | |
# upload.rb | |
class Upload < ApplicationRecord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# ... | |
has_many :upvotes | |
has_many :graffiti, through: :upvotes, source: :upvotable, source_type: "Graffiti" | |
has_many :uploads, through: :upvotes, source: :upvotable, source_type: "Upload" | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# graffiti.rb | |
class Graffiti < ActiveRecord::Base | |
has_many :uploads | |
has_many :upvotes, as: :upvotable | |
end | |
# upload.rb | |
class Upload < ApplicationRecord | |
belongs_to :user | |
belongs_to :graffiti |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# user.rb | |
class User < ActiveRecord::Base | |
has_many :upvotes | |
has_many :graffiti, through: :upvotes | |
end | |
# graffiti.rb | |
class Graffiti < ActiveRecord::Base | |
has_many :upvotes | |
has_many :users, through: :upvotes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In the initial code, I wasn't aware that let would create a new binding for | |
// each variable inside my loop. I assumed a closure around the setTimeout function | |
// was necessary to create new copy of the variables at each step. | |
animate() { | |
let previousDelay = 0; | |
let styles = null; | |
for (let sequence of this.dataSet) { | |
let delay = sequence[0] + previousDelay; | |
let objects = sequence.filter(this.isObject); | |
styles = this.formatStyles(objects); |
NewerOlder