Skip to content

Instantly share code, notes, and snippets.

View federicofazzeri's full-sized avatar

Federico Fazzeri federicofazzeri

  • canada
View GitHub Profile
@federicofazzeri
federicofazzeri / app.js
Last active October 16, 2017 16:07
Service worker setup for a PWA that shows cached data and replace it with fresh network data when available. If network data comes first, the view won't be updated with the old cached data. Cache/network data flows are managed with observables.
const dataUrl = ''; //your data api url
(function(dataUrl, Observable) {
'use strict';
/******** your impure functions: ***********/
//bind data to the view here
@federicofazzeri
federicofazzeri / app.js
Last active November 2, 2017 14:41
Workbox setup to alert your users that a new version of your PWA is available on their device
function checkForNewVersions() {
if( ! 'BroadcastChannel' in window) return;
const assetsUpdates = new BroadcastChannel('precache-updates');
const dataUpdates = new BroadcastChannel('data-updates');
assetsUpdates.addEventListener('message', (event) => {
/*alert the user to reload the page to get the new app version*/
});
dataUpdates.addEventListener('message', (event) => {
/*alert the user to reload the page to get the new app data*/
});
@federicofazzeri
federicofazzeri / .babelrc
Last active February 7, 2022 14:45
Node Express-based REST API (CRUD) using Firebase cloud Functions and FireStore cloud database + Babel config (The current Node version running in Cloud Functions is 6.10)
{
"presets": [
["env", {
"targets": {
"node": "6.10"
}
}]
]
}
@federicofazzeri
federicofazzeri / main.dart
Last active December 5, 2019 15:14
Flutter simple circle canvas animation (DartPad link https://dartpad.dev/905d84f36ebd0ee4b9bab2552564bf44)
import 'package:flutter/material.dart';
import 'dart:math';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@federicofazzeri
federicofazzeri / main.dart
Last active December 5, 2019 18:47
Flutter reactive UI without class based widgets (...but don't do this)
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
MyAppModel myAppModel = MyAppModel();
myAppModel.addListener(() => runApp(myApp(myAppModel)));
myAppModel.updateUI(1);
}