Skip to content

Instantly share code, notes, and snippets.

View alshdavid's full-sized avatar

David Alsh alshdavid

View GitHub Profile
@alshdavid
alshdavid / rx-subject.js
Created April 14, 2020 00:01
Simple Rxjs Subject
class Subject {
constructor() {
this.subscribers = {}
this.resolveComplete
this.completePromise = new Promise(res => this.resolveComplete = res)
this.hasComplete = false
}
toPromise() {
return this.completePromise
ROKT_DEBUG_KEY.placementInit({
"placement": {
"id": "6588",
"display": {
"targetElementSelector": "#rokt-placeholder"
},
"slots": [
{
"instanceGuid": "87339108-e107-430b-9dad-e33c32e2b1bc",
"offer": {
@alshdavid
alshdavid / README.md
Last active November 17, 2023 21:25
CBA PDF statement converter to PDF or CSV
@alshdavid
alshdavid / App.svelte
Created December 2, 2019 06:33
Context Wrapper Svelte
<script>
import { getContext } from 'svelte'
console.log(getContext('test')) // Foobar
</script>
import { Component, Initializer } from '@angular/core'
import { MyPipe } from './pipes'
import { AnotherComponent } from './components'
@Component({
selector: 'my-component',
declarations: [
MyPipe,
AnotherComponent
],
@alshdavid
alshdavid / ioc.ts
Last active September 11, 2019 00:35
class HTTPClient {
async get(url: string) {
return 'An HTTP Request!'
}
}
export default new HTTPClient()
import state from 'reallystate'
import immer from "immer"
import { Item } from './item'
export class Collection {
items = state.createCollection<Item[]>({
store: this.store,
collectionName: "posts",
defaultProcessor: immer,
initialValue: []
import { BehaviorSubject } from 'rxjs' // 3kb
export class Collection {
items = new BehaviorSubject<Item[]>([])
subscribe = this.items.subscribe.bind(this.items)
getValue() {
return this.items.getValue()
}
export class Collection {
items: Item[] = []
watchers = []
subscribe(cb: (value: Item[]) => void) {
this.watchers.push(cb)
cb(this.items)
return () => this.watchers.filter(sub => sub !== cb)
}
export class Item {
constructor(
public id: string,
public date: Date,
public title: string,
) {}
}
export class Collection {
items: Item[] = []