Skip to content

Instantly share code, notes, and snippets.

View ksimons's full-sized avatar

Kevin Simons ksimons

View GitHub Profile
@ksimons
ksimons / recoil-transactions.tsx
Created October 12, 2022 12:11
Using Recoil.js transactions
interface BulkItemCreator {
create(items: Array<{ id: string; name: string }>): void;
}
export function useBulkCreateExample() {
return useRecoilCallback(
({ transact_UNSTABLE }) =>
(callback: (creator: BulkItemCreator) => void) => {
transact_UNSTABLE(({ set, get }) => {
callback({
@ksimons
ksimons / using-equals-selector-family.tsx
Created October 12, 2022 12:10
Using equalSelectorFamily
const filteredWorkItemsByStatusSelector = equalSelectorFamily({
key: 'FiltereWorkItemsByStatus',
get:
({ spaceId, filterString }: { spaceId: string | undefined; filterString: string }) =>
({ get }) => {
const itemIds: string[] = getFilteredWorkItemsSomehow(get, spaceId, filterString);
return itemIds:
},
equals: _.isEqual,
});
@ksimons
ksimons / equals-selector-family.tsx
Created October 12, 2022 12:10
Recoil.js selector family that allows for equality checking
function equalSelectorFamily<T, P extends SerializableParam>(
options: EqualSelectorFamilyOptions<T, P>
) {
const inner = selectorFamily<T, P>({
key: `${options.key}_inner`,
get: options.get,
});
const priorValues: Map<P, T | undefined> = new Map();
@ksimons
ksimons / recoil-selectors.tsx
Created October 12, 2022 12:08
Recoil fine-grained selectors
const workItemTitleSelector = selectorFamily({
key: 'WorkItemTitle',
get:
(workItemId: string | undefined | null) =>
({ get }) => {
return get(workItems(workItemId)?.title;
},
});
// only fetch what we need!
function MyEditor() {
const editor = useMemo(() => withReact(createEditor()), []);
const [value, setValue] = React.useState<Node[]>([
{
children: [{ text: 'Testing' }],
},
]);
return (
<Slate editor={editor} value={value} onChange={(v) => setValue(v)}>
<Editable />
[
{
"type": "paragraph",
"children": [
{
"text": "Text with a link "
},
{
"type": "link",
"url": "https://kitemaker.co",
#!/usr/bin/env bash
# fork from https://gist.github.com/jakemhiller/d342ad51505addf78ec628a16fd3280f
changed_files="$(git diff-tree -r --name-only --no-commit-id $1 $2)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
U=${USER+", $USER"}
function helloWorld() {
`This template string ${x} is on
multiple lines.
`
function innerFunction() {
return 9 + 4;
}
return hello + innerFunction();
### Keybase proof
I hereby claim:
* I am ksimons on github.
* I am ksimons (https://keybase.io/ksimons) on keybase.
* I have a public key whose fingerprint is 28F4 A0A3 02CF 6CBC 7CD0 B1BF 0B9C 9048 FCE1 D4DE
To claim this, I am signing this object:
function Foo(val) {
this.value = val;
this.increment = function() {
this.value++;
}
}
var f = new Foo(11);
f.increment();