concept class in category node

appears as: classes, class, class, classes
Getting MEAN with Mongo, Express, Angular, and Node.js 2ED

This is an excerpt from Manning's book Getting MEAN with Mongo, Express, Angular, and Node.js 2ED.

Bootstrap offers a collection of elements and classes that you can use to create a sticky navigation bar that’s fixed to the top and collapses the options into a drop-down menu on mobile devices. We won’t explore the details of Bootstrap’s CSS classes here. All you need to do is grab the example code from the Bootstrap website, tweak it a little, and update it with the correct links.

A decorator is a way that ES2015 and TypeScript provide metadata and annotations to functions, modules and classes. A common use case in Angular is to handle dependency injection, which is a way of saying, “This module or class depends on this piece of functionality to run.”

This example is good and shows you the way forward, but you need a lot more data for a location and a better way to manage it. For this purpose, you need to use a class.

Listing 10.25. Defining, using, and exporting a class for reviews in locations.ts
export class Review {            #1
  author: string;
  rating: number;
  reviewText: string;
}

export class Location {
  _id: string;
  name: string;
  distance: number;
  address: string;
  rating: number;
  facilities: string[];
  reviews: Review[];             #2
  coords: number[];
  openingTimes: OpeningTimes[];
}
Isomorphic Web Applications: Universal Development with React

This is an excerpt from Manning's book Isomorphic Web Applications: Universal Development with React.

Listing 2.5. App (top-level component)—src/components/app.jsx
import React from 'react'; import Recipes from './recipes'; import Featured from './featured'; class App extends React.Component { #1 render() { #2 return ( <div> <div className="ui fixed inverted menu"> <div className="ui container"> <a href="/" className="header item"> Recipes Example App </a> </div> </div> <div className="ui grid"> <Recipes {...this.props}/> #3 <Featured {...this.props.featuredRecipe}/> #3 </div> <div className="ui inverted vertical footer segment"> Footer </div> </div> ); } } export default App; #1 To declare a React component that uses state, create a class that extends the base component class. #2 Every component that has a render function, must return either null or valid JSX. #3 A component defines the layout of its children. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":4,\"ch\":63},{\"line\":4,\"ch\":65}],[{\"line\":30,\"ch\":0},{\"line\":30,\"ch\":2}],[{\"line\":6,\"ch\":63},{\"line\":6,\"ch\":65}],[{\"line\":31,\"ch\":0},{\"line\":31,\"ch\":2}],[{\"line\":17,\"ch\":64},{\"line\":17,\"ch\":66}],[{\"line\":18,\"ch\":64},{\"line\":18,\"ch\":66}],[{\"line\":32,\"ch\":0},{\"line\":32,\"ch\":2}],[{\"line\":17,\"ch\":64},{\"line\":17,\"ch\":66}],[{\"line\":18,\"ch\":64},{\"line\":18,\"ch\":66}],[{\"line\":32,\"ch\":0},{\"line\":32,\"ch\":2}]]"} !@%STYLE%@!
  • Semantic UI— Simplify the CSS by providing a standard set of classes. The focus of this book isn’t CSS, so this will make following along in the various examples easier.
  • When adding CSS classes in JSX, the compiler will ignore the word class because it’s a reserved word in JavaScript. Remember that the JSX code will get compiled to JavaScript. Instead, you need to use the attribute className to add a class:

    3.5.1. Using classes

    The Tab components are going to be interactive and will need to have methods for handling clicks. For components that aren’t pure functional components, React provides a class that can be extended. That gives you the benefit of access to several built-in React lifecycle methods and the other React component API methods such as setState. The following listing shows the code for the Tab component, which should be added to the tabs.jsx file in the todo folder.

    Node.js in Practice

    This is an excerpt from Manning's book Node.js in Practice.

    You can inherit from EventEmitter to make your own event-based APIs. Let’s say you’re working on a PayPal payment-processing module. You could make it event-based, so instances of Payment objects emit events like paid and refund. By designing the class this way, you decouple it from your application logic, so you can reuse it in more than one project.

    Now Node has reached a point where the core developers have seen the types of problems people are tackling with streams, so the new API is richer thanks to the new stream primitive classes. Table 5.1 shows a summary of the classes available from Node 0.10 onward.

    Table 5.1. A summary of the classes available in streams2

    Name

    User methods

    Description

    stream.Readable _read(size) Used for I/O sources that generate data
    stream.Writable _write(chunk, encoding, callback) Used to write to an underlying output destination
    stream.Duplex _read(size), _write(chunk, encoding, callback) A readable and writable stream, like a network connection
    stream.Transform _flush(size), _transform(chunk, encoding, callback) A duplex stream that changes data in some way, with no limitation on matching input data size with the output

    Built-in streams and the classes used to build custom streams allow the internal buffer size to be configured. It’s useful to know how to optimize this value to attain the desired performance characteristics.