This file contains hidden or 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
const ref = new Firebase('<my-firebase-app>/items'); | |
// Create a push reference (no data has been sent to the server, just a generated id) | |
const childRef = ref.push(); | |
// create an object and with they push-id | |
const data = { name: 'David': key: childRef.key() }; | |
// save it | |
childRef.set(data); | |
// Listen for the update | |
childRef.on('value', (snap) => console.log(snap.val())); |
This file contains hidden or 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
/** | |
* Increases view count by one. | |
* @param: db {FirebaseDatabase} - Firebase Database instance | |
* @param: id {String} - id of post | |
* @return: Promise<{committed: boolean, snapshot: nullable firebase.database.DataSnapshot}> | |
* @docs: https://firebase.google.com/docs/reference/js/firebase.database.Reference#transaction | |
*/ | |
const incrementViews = (db, id) => { | |
const ref = db.ref('views').child(id) | |
return ref.transaction(currentViews => { |
This file contains hidden or 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 * as firebase from 'firebase/app'; // Provides firebase-app.js only | |
import 'firebase/auth'; // Not named, just naked | |
const app = firebase.initializeApp({ }); | |
console.log(app.auth()); // auth object | |
console.log(app.database()); // undefined |
This file contains hidden or 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 { angularUniversal } from 'angular-universal-express'; | |
import * as express from 'express'; | |
const app = express(); | |
/* | |
I usually copy my Angular CLI "dist" build into my "dist-server" build | |
and serve them as static files so they aren't treated as dynamic routes. | |
*/ | |
app.use(express.static(__dirname + '/dist')); | |
app.get('/*', angularUniversal({ |
This file contains hidden or 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
# Build the browser bundle | |
ng build --prod | |
# Build the universal bundle | |
ng build --prod --app 1 | |
# Move the browser index.html to generate the SSR version | |
mv dist/index.html dist-server/ | |
# Treat dist as static within dist-server | |
mv dist/ dist-server/static |
This file contains hidden or 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
# Build the browser bundle | |
ng build --prod | |
# Build the universal bundle | |
ng build --prod --app 1 | |
# Move the browser index.html to generate the SSR version | |
mv dist/index.html dist-server/ | |
# Treat dist as static within dist-server | |
mv dist/ dist-server/static | |
# Transpile TS server code | |
node_modules/.bin/tsc -p server/tsconfig.json |
This file contains hidden or 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
Show hidden characters
{ | |
"compilerOptions": { | |
"outDir": "../dist-server", | |
"sourceMap": true, | |
"moduleResolution": "node", | |
"target": "es5", | |
"lib": [ "es2017" ] | |
} | |
} |
This file contains hidden or 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 { angularUniversal } from 'angular-universal-express'; | |
import * as express from 'express'; | |
const app = express(); | |
// serving static requests | |
app.use(express.static(__dirname + '/static')); | |
// serving dynamic requests | |
app.get('/*', angularUniversal({ | |
index: __dirname + '/index.html', | |
main: __dirname + '/main.<your-hash>.bundle', |
This file contains hidden or 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
function selectText(selection) { | |
var range = selection.getRangeAt(0); | |
function replaceRange(s, start, end, substitute) { | |
return s.substring(0, start) + substitute + s.substring(end); | |
} | |
var text = selection.baseNode.textContent.substring(range.startOffset, range.endOffset); | |
var mark = `<mark>${text}</mark>`; | |
range.startContainer.parentElement.innerHTML = replaceRange(range.startContainer.textContent, range.startOffset, range.endOffset, mark); | |
} |