Skip to content

Instantly share code, notes, and snippets.

View darrenmothersele's full-sized avatar
🏠
Working from home

Darren Mothersele darrenmothersele

🏠
Working from home
View GitHub Profile
import { TodoActions } from './todo.actions';
import { Task } from './interfaces/task.interface';
import produce from 'immer';
export const initialState: Array<Task> = [];
export const producer = (draft, action) => TodoActions.match(action, {
NewTask: task => {
draft.push(task);
},
import { unionize, ofType } from 'unionize';
import { Task } from './interfaces/task.interface';
export const TodoActions = unionize({
NewTask: ofType<Task>(),
ToggleTask: ofType<{ id: string }>(),
ClearCompleted: {}
}, { tag: 'type', value: 'payload' });
import { Action } from '@ngrx/store';
import { ActionTypes } from './counter.actions';
export const initialState = 0;
export function counterReducer(state = initialState, action: Action) {
switch (action.type) {
case ActionTypes.Increment:
return state + 1;
import { Action } from '@ngrx/store';
export enum ActionTypes {
Increment = '[Counter Component] Increment',
Decrement = '[Counter Component] Decrement',
Reset = '[Counter Component] Reset',
}
export class Increment implements Action {
readonly type = ActionTypes.Increment;
import { Actions } from './counter.actions';
import produce from 'immer';
export const initialState = 0;
const producer = (draft, action) => Actions.match(action, {
Increment: () => draft + 1,
Decrement: () => draft - 1,
Reset: () => initialState,
default: () => {}
import { unionize } from 'unionize';
export const Actions = unionize({
Increment: {},
Decrement: {},
Reset: {},
}, { tag: 'type' });
// This is added globally by the zip.js library
declare const zip: any;
@Injectable()
export class ZipService {
constructor() {
zip.workerScriptsPath = 'scripts/';
}
export interface ZipEntry {
version: number;
bitFlag: number;
compressionMethod: number;
lastModDateRaw: number;
lastModDate: string;
crc32: number;
compressedSize: number;
uncompressedSize: number;
filenameLength: number;
service firebase.storage {
match /b/{bucket}/o {
match /{userId}/{document=**} {
allow read: if request.auth.uid == userId;
allow write: if request.auth.uid == userId
&& request.auth.token.path == request.resource.name
&& request.auth.token.remaining >= request.resource.size;
}
}
}
@darrenmothersele
darrenmothersele / upload-with-get-quota.ts
Created December 19, 2018 18:30
upload-with-get-quota.ts
// Three observables
const getQuota$ = this.functions.httpsCallable('getQuotaToken')({ id });
const signIn$ = token => this.userService.signInWithToken(token);
const doUpload$ = this.doFileUpload(userId, id, file);
// Combine
getQuota$.pipe(
concatMap(({ token }) => signIn$(token)),
concatMap(() => doUpload$)
);