Adding server-side functions to my tiny responsive web apps

  • I only want to pay for what I use (scale-to-zero)
  • I don’t have a lot of time available for learning or building (no steep learning curves without substantial time-savings)
  • I don’t have time for maintenance activities (no patching servers, automated scale-up)
  • I’m not a good UI designer or front end engineer (design systems are great)

The business problem

  • A timed, unguided meditation
  • Ability to continue when the timer has finished if wanted
  • Ability to pause and resume a session
  • A calming, ambient, background sound loop
  • A periodic bell to check I’m still in the moment
  • Random intermittent, but relevant, sounds
  • An automatic diary of sessions

The new requirement

Firebase triggers

exports.countStreaks = functions.database.ref('diary/{userUid}/entries')
.onUpdate(async (snapshot, context) => {
const afterEntries = Object.entries(snapshot.after.val());
const processedEntries = [];

for (const [key, value] of afterEntries) {
const finishTime = DateTime.fromMillis(value.finishTime);
const diaryEntry = {finishTime, totalSeconds: value.totalSeconds};
processedEntries.push(diaryEntry);
}
const stats = statscalculator.longestStreak(userTimezone, processedEntries);
if(stats){
return snapshot.after.ref.parent.child('stats').set(stats);
}
});

Summary

--

--

--

Technology leader for Xero in Auckland, New Zealand, former start-up founder, father of two, maker of t-shirts and small software products

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Shield Platform Encryption for ISV: Part One

Adding Python to your life — Choices everywhere!

I created an automated WhatsApp reply bot!

How to organise your PhD notes

My internship experience with Facebook, London

Fix Rails ActiveStorage URI InvalidError

My first experience on GSoC 2021 with OpenMRS

3 Essential Things For Beginner Kernel Developers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gareth Cronin

Gareth Cronin

Technology leader for Xero in Auckland, New Zealand, former start-up founder, father of two, maker of t-shirts and small software products

More from Medium

How to use Retool with AWS Amplify (AppSync and Cognito)

Building a Web App with Neo4j AuraDB and PHP

Magento Global Reference Architecture Terraform Infrastructure as Code (IaC) on AWS Cloud

When Less is More: Serverless NAT Gateway — Part 1