Skip to content

Commit

Permalink
improved get config
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Apr 11, 2024
1 parent 322f2d4 commit a1b0a97
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 105 deletions.
5 changes: 2 additions & 3 deletions src/lib/core/MRPConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NDK, { NDKEvent, NDKKind, NDKRelaySet } from "@nostr-dev-kit/ndk";
import NDK, { NDKEvent, NDKKind, NDKRelaySet, NDKSubscription } from "@nostr-dev-kit/ndk";
import { AppConfig } from "./kinds/app-config";

import type { EventEmitter } from 'tseep';
Expand All @@ -16,7 +16,6 @@ export class MRPConfig extends MRPData {
private _event: AppConfig | null;
private _data: any;
private _pubkey: string | undefined;
private _operator: MRPUser | undefined
private _relay: string | undefined

constructor($state: MRPState, relay?: string, pubkey?: string){
Expand Down Expand Up @@ -49,7 +48,7 @@ export class MRPConfig extends MRPData {
(await this.$.ndk
.fetchEvent(
{ kinds: [NDKKind.AppSpecificData], authors: [this.pubkey], '#d': [this.configKey()] },
{ unrefUnsubscribeTimeout: 1000 },
undefined,
this._relay? NDKRelaySet.fromRelayUrls([this._relay], this?.$?.ndk as NDK): undefined
)
) as AppConfig
Expand Down
104 changes: 2 additions & 102 deletions src/lib/core/kinds/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class AppConfig extends NDKEvent {
return json
}

get(key: string): any | undefined {
return this._config?.[key]
get(key?: string): any | undefined {
return key? this._config?.[key]: this._config
}

set(key: string, payload: Json){
Expand All @@ -69,104 +69,4 @@ export class AppConfig extends NDKEvent {
this.content = jsonpack.pack(json)
}

// get colors(): Colors | undefined{
// const result = new Object() as Colors;
// (this.tags as ColorTuple[])
// .filter( (tag: ColorTuple) => tag[0] === 'color')
// .forEach( (tag: ColorTuple) => {
// result[tag[1]] = String(tag[2])
// })
// return result;
// }

// set backgroundColor(color: string){
// this.removeByKeyAndValue('color', 'background')
// this.tags.push(["color", 'background', color]);
// }

// get backgroundColor(): string | undefined{
// return this.tags.find( (tag: NDKTag) => tag[1] === 'background')?.[2]
// }

// set foregroundColor(color: string){
// this.removeByKeyAndValue('color', 'foreground')
// this.tags.push(["color", 'foreground', color]);
// }

// get foregroundColor(): string | undefined{
// return this.tags.find( (tag: NDKTag) => tag[1] === 'foreground')?.[2]
// }

// set primaryColor(color: string){
// this.removeByKeyAndValue('color', 'primary')
// this.tags.push(["color", 'primary', color]);
// }

// get primaryColor(): string | undefined{
// return this.tags.find( (tag: NDKTag) => tag[1] === 'primary')?.[2]
// }

// set secondaryColor(color: string){
// this.removeByKeyAndValue('color', 'secondary')
// this.tags.push(["color", 'secondary', color]);
// }

// get secondaryColor(): string | undefined{
// return this.tags.find( (tag: NDKTag) => tag[1] === 'secondary')?.[2]
// }

// set accentColor(color: string){
// this.removeByKeyAndValue('color', 'accent')
// this.tags.push(["color", 'accent', color]);
// }

// get accentColor(): string | undefined{
// return this.tags.find( (tag: NDKTag) => tag[1] === 'accent')?.[2]
// }

// set mutedColor(color: string){
// this.removeByKeyAndValue('color', 'muted')
// this.tags.push(["color", 'muted', color]);
// }

// get mutedColor(): string | undefined{
// return this.tags.find( (tag: NDKTag) => tag[1] === 'muted')?.[2]
// }

// get font(): Font | undefined{
// return this._font
// }

// set font(font: Font){
// this._font = font
// }

// get theme(): string | undefined{
// return this._theme
// }

// set theme(theme: string){
// this._theme = theme
// }

// get visible(): ComponentVisible | undefined{
// const result = new Object() as ComponentVisible;
// (this.tags)
// .filter( (tag: NDKTag) => tag[0] === 'visible')
// .forEach( (tag: NDKTag) => {
// result[tag[1]] = true
// })
// return result;
// }

// set visible(visible: ComponentVisible ){
// for (const key in visible){
// this.removeByKeyAndValue('visible', key)
// this.tags.push(["visible", key, 'true']);
// }
// }

// private removeByKeyAndValue(key: string, value: string){
// this.tags = this.tags.filter( (tag: NDKTag) => tag[0] === key && tag[1] !== value)
// }
}

0 comments on commit a1b0a97

Please sign in to comment.