Skip to content

Instantly share code, notes, and snippets.

View enyo's full-sized avatar
🙌
Primarily working on Pausly

Mat Simon enyo

🙌
Primarily working on Pausly
View GitHub Profile
@enyo
enyo / event-target.ts
Created October 8, 2022 15:45
TypeScript TypedEventTarget
/**
* Implements the EventTarget, but with type safety.
*
* Extend this class with an object that describes your events like this:
*
* type AccountEvents = {
* logout: null
* 'sign-in': { username: string; password: string }
* }
* class Account extends TypedEventTarget<AccountEvents> {
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import svelte from 'rollup-plugin-svelte'
import { terser } from 'rollup-plugin-terser'
import sveltePreprocess from 'svelte-preprocess'
const production = !process.env.ROLLUP_WATCH
export default {
@enyo
enyo / web-components.ts
Last active June 23, 2023 22:46
Svelte Web Components
import HeaderMenu from './lib/components/HeaderMenu.svelte'
import type { SvelteComponent } from 'svelte'
customElements.define(
// I recommend prefixing your custom elements, but for this example
// I'm keeping it simple.
'header-menu',
class extends HTMLElement {
_element: SvelteComponent;
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
@enyo
enyo / deploy.yaml
Last active October 14, 2021 17:21
jobs:
build:
# ...
test:
# ...
deploy:
# Only run if merged to main.
if: github.ref == 'refs/heads/main'
# Only deploy if all tests passed.
@enyo
enyo / test.yaml
Last active October 14, 2021 17:20
jobs:
build:
# Everything from the last section
test:
# We depend on the build step for this.
needs: build
timeout-minutes: 15
runs-on: ubuntu-latest
# We need to use the cypress container here, that includes chrome and
@enyo
enyo / build.yaml
Last active October 14, 2021 17:20
jobs:
build:
# We're running on ubuntu-latest, nothing special
runs-on: ubuntu-latest
steps:
# As usual, we simply checkout the project
- name: Checkout
uses: actions/checkout@v2
# This action is provided by Cypress. It installs node and the NPM
class AccountService extends AccountServiceBase {
@override
Future<Empty> sendEmailVerification(ServiceCall call, VerificationRequest request) {
// TODO: implement sendEmailVerification
throw UnimplementedError();
}
@override
Future<User> signInWithPassword(ServiceCall call, PasswordSignInRequest request) {
// TODO: implement signInWithPassword
/// A channel that the gRPC libray communicates over.
/// This is provided by the gRPC library.
final channel = GrpcWebClientChannel.xhr(Uri.parse('https://your.api.url:8080'));
/// The class [AccountServiceClient] is generated by the gRPC library from
/// your `.proto` definition.
final client = AccountServiceClient(channel);
Future<void> changePassword() async {
/// The message you want to send to the API. It's also generated from your
syntax = "proto3";
package dropzone.public_account;
import "shared.proto";
// Very simplified version of our account service.
service AccountService {
rpc SendEmailVerification(VerificationRequest) returns(shared.Empty);