This file contains 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 processUser = functions.firestore | |
.document("accounts/{accountId}/users/{userId}") | |
.onCreate(async (snapshot, context) => { | |
try { | |
await processTheUser(snapshot); | |
const event = new UserProcessed(snapshot); | |
await new Account(context.params.accountId).addEvent(event); | |
} catch (error) { | |
const event = new UserProcessingFailed(snapshot, error); | |
await new Account(context.params.accountId).addEvent(event); |
This file contains 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
class Account { | |
constructor(protected accountId: string) {} | |
public async addEvent(event: Event) { | |
return firestore() | |
.collection("accounts") | |
.doc(this.accountId) | |
.collection("events") | |
.add({ | |
name: event.getName(), |
This file contains 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
interface Event { | |
public isCritical(): boolean; | |
public getName(): string; | |
public getPayload(): object; | |
} | |
class UserProcessed implements Event { | |
constructor(protected user: firestore.DocumentSnapshot) {} | |
public isCritical() { |
This file contains 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 processUser = functions.firestore | |
.document("accounts/{accountId}/users/{userId}") | |
.onCreate(async (snapshot, context) => { | |
await processTheUser(snapshot); | |
const event = new UserProcessed(snapshot); | |
await new Account(context.params.accountId).addEvent(event); | |
}) |
This file contains 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
interface Broadcaster { | |
send(event: Event, user: User) | |
} | |
class EmailBroadcaster implements Broadcaster { | |
send(event: Event, user: User) { | |
const description = `New event ${event.name} occured at ${event.getTimestamp()}` | |
emailService.send({ to: user.email, subject: event.name, body: description }) | |
} | |
} |
This file contains 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
class EmailBroadcaster { | |
send(event: Event, user: User) { | |
const description = `New event ${event.name} occured at ${event.getTimestamp()}` | |
emailService.send({ to: user.email, subject: event.name, body: description }) | |
} | |
} | |
class NotificationHandler { | |
private mailer: EmailBroadcaster |
This file contains 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
interface CanBroadcast { | |
send(event: Event, user: User) | |
} | |
interface CanTrackReads { | |
trackReads(track: boolean); | |
} | |
class EmailBroadcaster implements CanBroadcast, CanTrackReads { | |
send(event: Event, user: User) { |
This file contains 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
interface CanBroadcast { | |
send(event: Event, user: User) | |
trackReads(track: boolean) | |
} | |
class EmailBroadcaster implements CanBroadcast { | |
send(event: Event, user: User) { | |
emailService.send({ to: user.email, subject: event.name }) | |
} | |
trackReads(track: boolean) { |
This file contains 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
<?php | |
namespace Tests; | |
use Storage; | |
use Illuminate\Filesystem\Filesystem; | |
trait CreatesFakeStorage | |
{ | |
/** |
This file contains 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
<?php | |
// ... | |
public static function fake($disk = null, array $config = []) { | |
$disk = $disk ?: static::$app['config']->get('filesystems.default'); | |
(new Filesystem)->cleanDirectory( | |
$root = storage_path('framework/testing/disks/'.$disk) | |
); |
NewerOlder