types: fixing type issues and updating grid glob

This commit is contained in:
Hunter Miller 2021-08-31 14:59:32 -05:00
parent 0b22ee3bb5
commit 0351220374
7 changed files with 46 additions and 40 deletions

View File

@ -1,7 +1,7 @@
:~ title+'Grid'
info+'An app launcher for urbit.'
color+0xee.5432
glob+'https://bootstrap.urbit.org/glob-0v6.7fo6n.0gnm6.k5ekb.cv17k.uen5j.glob'
glob+'https://bootstrap.urbit.org/glob-0v6.t43bu.cpl0b.bsisc.sqr4d.dckpn.glob'
base+'grid'
version+[0 0 1]
website+'https://tlon.io'

View File

@ -1,4 +1,4 @@
import { chadIsRunning } from '@urbit/api/docket';
import { chadIsRunning, Treaty } from '@urbit/api/docket';
import clipboardCopy from 'clipboard-copy';
import React, { FC } from 'react';
import cn from 'classnames';
@ -8,12 +8,14 @@ import { Dialog, DialogClose, DialogContent, DialogTrigger } from './Dialog';
import { DocketHeader } from './DocketHeader';
import { Spinner } from './Spinner';
import { VatMeta } from './VatMeta';
import useDocketState, { App } from '../state/docket';
import useDocketState, { ChargeWithDesk } from '../state/docket';
import { getAppHref } from '../state/util';
import { addRecentApp } from '../nav/search/Home';
import { TreatyMeta } from './TreatyMeta';
type InstallStatus = 'uninstalled' | 'installing' | 'installed';
type App = ChargeWithDesk | Treaty;
interface AppInfoProps {
docket: App;
vat?: Vat;

View File

@ -4,7 +4,7 @@ import cn from 'classnames';
interface DocketImageProps extends Pick<Docket, 'color' | 'image'> {
className?: string;
sizing: 'small' | 'full';
sizing?: 'small' | 'full';
}
export function DocketImage({ color, image, className = '', sizing = 'full' }: DocketImageProps) {

View File

@ -14,7 +14,7 @@ import { ProviderLink } from '../../components/ProviderLink';
import { DocketWithDesk, useCharges } from '../../state/docket';
import { getAppHref } from '../../state/util';
interface RecentsStore {
export interface RecentsStore {
recentApps: DocketWithDesk[];
recentDevs: Provider[];
addRecentApp: (app: DocketWithDesk) => void;

View File

@ -1,7 +1,14 @@
import { useLeapStore } from './nav/Nav';
import { useRecentsStore } from './nav/search/Home';
import useDocketState from './state/docket';
declare global {
interface Window {
ship: string;
desk: string;
recents: typeof useRecentsStore.getState;
docket: typeof useDocketState.getState;
leap: typeof useLeapStore.getState;
}
}

View File

@ -1,5 +1,5 @@
import produce, { immerable, castImmutable, castDraft, setAutoFreeze, enablePatches } from 'immer';
import bigInt, { BigInteger } from "big-integer";
import produce, { immerable, castDraft, setAutoFreeze, enablePatches } from 'immer';
import bigInt, { BigInteger } from 'big-integer';
setAutoFreeze(false);
@ -24,16 +24,16 @@ function sorted(a: BigInteger[], b: BigInteger[], reversed = false) {
if (reversed) {
return getSort * -1;
} else {
return getSort
return getSort;
}
}
export function sortBigIntArr(a: BigInteger[], b: BigInteger[]) {
let aLen = a.length;
let bLen = b.length;
const aLen = a.length;
const bLen = b.length;
let aCop = a.slice(0);
let bCop = b.slice(0);
const aCop = a.slice(0);
const bCop = b.slice(0);
aCop.reverse();
bCop.reverse();
@ -47,14 +47,13 @@ export function sortBigIntArr(a: BigInteger[], b: BigInteger[]) {
i++;
}
}
return bLen - aLen;
}
export default class BigIntArrayOrderedMap<V> implements Iterable<[BigInteger[], V]> {
root: Record<string, V> = {}
cachedIter: [BigInteger[], V][] = null;
cachedIter: [BigInteger[], V][] | null = null;
[immerable] = true;
reversed = false;
@ -69,34 +68,33 @@ export default class BigIntArrayOrderedMap<V> implements Iterable<[BigInteger[],
return Object.keys(this.root).length;
}
get(key: BigInteger[]) {
return this.root[arrToString(key)] ?? null;
}
gas(items: [BigInteger[], V][]) {
return produce(this, draft => {
return produce(this, (draft) => {
items.forEach(([key, value]) => {
draft.root[arrToString(key)] = castDraft(value);
});
draft.generateCachedIter();
},
},
(patches) => {
//console.log(`gassed with ${JSON.stringify(patches, null, 2)}`);
// console.log(`gassed with ${JSON.stringify(patches, null, 2)}`);
});
}
set(key: BigInteger[], value: V) {
return produce(this, draft => {
return produce(this, (draft) => {
draft.root[arrToString(key)] = castDraft(value);
draft.cachedIter = null;
});
}
clear() {
return produce(this, draft => {
return produce(this, (draft) => {
draft.cachedIter = [];
draft.root = {}
draft.root = {};
});
}
@ -105,7 +103,7 @@ export default class BigIntArrayOrderedMap<V> implements Iterable<[BigInteger[],
}
delete(key: BigInteger[]) {
const result = produce(this, draft => {
const result = produce(this, (draft) => {
delete draft.root[arrToString(key)];
draft.cachedIter = null;
});
@ -114,7 +112,7 @@ export default class BigIntArrayOrderedMap<V> implements Iterable<[BigInteger[],
[Symbol.iterator](): IterableIterator<[BigInteger[], V]> {
let idx = 0;
let result = this.generateCachedIter();
const result = this.generateCachedIter();
return {
[Symbol.iterator]: this[Symbol.iterator],
next: (): IteratorResult<[BigInteger[], V]> => {
@ -122,7 +120,7 @@ export default class BigIntArrayOrderedMap<V> implements Iterable<[BigInteger[],
return { value: result[idx++], done: false };
}
return { done: true, value: null };
},
}
};
}
@ -144,7 +142,7 @@ export default class BigIntArrayOrderedMap<V> implements Iterable<[BigInteger[],
if(this.cachedIter) {
return [...this.cachedIter];
}
const result = Object.keys(this.root).map(key => {
const result = Object.keys(this.root).map((key) => {
return [stringToArr(key), this.root[key]] as [BigInteger[], V];
}).sort(([a], [b]) => sorted(a, b, this.reversed));
this.cachedIter = result;

View File

@ -1,5 +1,5 @@
import produce, { immerable, castImmutable, castDraft, setAutoFreeze, enablePatches } from 'immer';
import bigInt, { BigInteger } from "big-integer";
import produce, { immerable, castDraft, setAutoFreeze, enablePatches } from 'immer';
import bigInt, { BigInteger } from 'big-integer';
setAutoFreeze(false);
@ -16,7 +16,7 @@ function sortBigInt(a: BigInteger, b: BigInteger) {
}
export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
root: Record<string, V> = {}
cachedIter: [BigInteger, V][] = null;
cachedIter: [BigInteger, V][] | null = null;
[immerable] = true;
constructor(items: [BigInteger, V][] = []) {
@ -32,34 +32,33 @@ export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
return this.generateCachedIter().length;
}
get(key: BigInteger) {
return this.root[key.toString()] ?? null;
}
gas(items: [BigInteger, V][]) {
return produce(this, draft => {
return produce(this, (draft) => {
items.forEach(([key, value]) => {
draft.root[key.toString()] = castDraft(value);
});
draft.cachedIter = null;
},
},
(patches) => {
//console.log(`gassed with ${JSON.stringify(patches, null, 2)}`);
// console.log(`gassed with ${JSON.stringify(patches, null, 2)}`);
});
}
set(key: BigInteger, value: V) {
return produce(this, draft => {
return produce(this, (draft) => {
draft.root[key.toString()] = castDraft(value);
draft.cachedIter = null;
});
}
clear() {
return produce(this, draft => {
return produce(this, (draft) => {
draft.cachedIter = [];
draft.root = {}
draft.root = {};
});
}
@ -68,7 +67,7 @@ export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
}
delete(key: BigInteger) {
const result = produce(this, draft => {
const result = produce(this, (draft) => {
delete draft.root[key.toString()];
draft.cachedIter = null;
});
@ -77,7 +76,7 @@ export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
[Symbol.iterator](): IterableIterator<[BigInteger, V]> {
let idx = 0;
let result = this.generateCachedIter();
const result = this.generateCachedIter();
return {
[Symbol.iterator]: this[Symbol.iterator],
next: (): IteratorResult<[BigInteger, V]> => {
@ -85,7 +84,7 @@ export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
return { value: result[idx++], done: false };
}
return { done: true, value: null };
},
}
};
}
@ -107,7 +106,7 @@ export default class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
if(this.cachedIter) {
return [...this.cachedIter];
}
const result = Object.keys(this.root).map(key => {
const result = Object.keys(this.root).map((key) => {
const num = bigInt(key);
return [num, this.root[key]] as [BigInteger, V];
}).sort(([a], [b]) => sortBigInt(a,b));