Front End Flashcards
What is the DOM
Document Object Model
- It’s a programming interface that represents the web page as nodes and takes the raw HTMl and JS to represent the page state.
- The nodes can then be manipulated through JS (ex: event listeners)
- DOM is not a language
- Makes structural representation of the webpage language agnostic w/ consistent API
What is CORS?
Cross origin resource sharing
CORS is mechanism where additional HTTP requests are made to access resources on another domain than the current site.
For security, browsers restrict HTTP requests initiated from within scripts.
CORS headers must be used to get around this.
Could maybe learn deeper on security risks and mitigation measures built into browsers.
Media Queries
A useful tool for when you want to apply css selectively based on the device the site is being viewed on.
ex:
@media screen and (min-width: 30em) and (orientation: landscape) { … }
ex2: @media only screen and (max-width: 500px) { body { background-color: lightblue; } }
ex3: /* For mobile phones: */ [class*="col-"] { width: 100%; } @media only screen and (min-width: 600px) { /* For tablets: */ .col-m-1 {width: 8.33%;} ... etc } @media only screen and (min-width: 768px) { /* For desktop: */ .col-1 {width: 8.33%;} ... etc }
reference:
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
Isomorphic rendering
In short it refers to the ability to render both on the backend and front end (individually)
In an isomorphic application, the first request made by the web browser is processed by the server while subsequent requests are processed by the client.
Virtual DOM
Used in react and is compared to actual DOM state to force a re-render. (Local, simplified version of the DOM allowing it to be faster than actual DOM manipulations)
Add more!
React element
This is what a react component is converted to for insertion into the virtual DOM.
React Components
Components can just be thought of as javascript that produces html. (like jsx)
Block-level element
Block level elements begin on new lines.
May contain inline elements and other block elements.
ex:
<p>a paragraph is a kind of block</p>
Inline element
Only occupies the the “space” within the tags they are bound. Does not contain other elements either.
ex:
<span>spans are inline</span>
inline styling is somewhat frowned upon…
What is a declarative programming?
SQL ,HTML, and CSS are declarative languages.
Like functional programming, there are no side-effects.
Any style of programming that is not imperative.
Declarative programming describe the desired results without listing the steps that must be performed to reach those results.
More of a WHAT rather than a HOW.
**Most declarative solutions are an abstraction over some imperative implementation.
React - App.js
AND functional component vs. class component
import React from ‘react’;
import {component} from ‘react’;
export default class App extends Component { render() { return ( <div>Sample contents!</div> ) } }
ORRR
import React from ‘react’;
(CLASS BASED component) class App extends React.Component { const App = () => ( render() ( <div>Stuff.</div> ) }
(functional component)
const App = () => (
<div>Stuff.</div>
)
export default App;
Note:
React needs to be imported because js conversion uses React.createElement….
how to access contents in event handler function (ex: input text)?
class Example extends React.Component { render() (
)
}
handleInputChange(e) {
console.log(e.target.value);
}
WITH STATE:
class Example extends React.Component { constructor(props) { super(props); this.state = { term: "" }; }
render() ( this.setState({term: e.target.value})} /> ) }
controlled component
A component that takes it’s value from the state.
example:
render() ( this.setState({term: e.target.value})} /> )
in this case, input is a controlled component since it takes its value from the state!
Note:
This is an example of declarative code.
es6 shorthand for when key and property have the same name?
ex:
video => this.setState({video: video})
can be rewritten as:
video => this.setState({video})
ex2: const VideoListItem = (props) => { const video = props.video;
return <li>Whatever you want.</li> }
CAN BE REWRITTEN
const VideoListItem = ({video}) => { //note that props is still being passed in
return <li>Whatever you want.</li> }
Pass down callbacks as props in React
You can pass a function as a prop in order to collect a “selection” from a child component for the purpose of updating the parent and/or sibling component
AKA threading methods/functions