interface: basic new contact-store support

This commit is contained in:
Logan Allen 2021-01-19 13:56:17 -06:00
parent cdb91291ed
commit 6d95cc76a4
3 changed files with 44 additions and 44 deletions

View File

@ -5,52 +5,52 @@ import { ContactUpdate } from '~/types/contact-update';
type ContactState = Pick<StoreState, 'contacts'>;
export default class ContactReducer<S extends ContactState> {
reduce(json: Cage, state: S) {
const data = _.get(json, 'contact-update', false);
if (data) {
this.initial(data, state);
this.add(data, state);
this.remove(data, state);
this.edit(data, state);
}
export const ContactReducer = (json, state) => {
const data = _.get(json, 'contact-update', false);
if (data) {
console.log(data);
initial(data, state);
add(data, state);
remove(data, state);
edit(data, state);
console.log(state);
}
};
initial(json: ContactUpdate, state: S) {
const data = _.get(json, 'initial', false);
if (data) {
state.contacts = data;
}
const initial = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'initial', false);
if (data) {
state.contacts = data;
}
};
add(json: ContactUpdate, state: S) {
const data = _.get(json, 'add', false);
if (data) {
state.contacts[data.ship] = data.contact;
}
const add = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'add', false);
if (data) {
state.contacts[data.ship] = data.contact;
}
};
remove(json: ContactUpdate, state: S) {
const data = _.get(json, 'remove', false);
if (
data &&
(data.ship in state.contacts)
) {
delete state.contacts[data.ship];
}
const remove = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'remove', false);
if (
data &&
(data.ship in state.contacts)
) {
delete state.contacts[data.ship];
}
};
edit(json: ContactUpdate, state: S) {
const data = _.get(json, 'edit', false);
if (
data &&
(data.ship in state.contacts)
) {
const edit = Object.keys(data['edit-field']);
if (edit.length !== 1) {
return;
}
state.contacts[data.ship][edit[0]] = data['edit-field'][edit[0]];
const edit = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'edit', false);
if (
data &&
(data.ship in state.contacts)
) {
const edit = Object.keys(data['edit-field']);
if (edit.length !== 1) {
return;
}
state.contacts[data.ship][edit[0]] = data['edit-field'][edit[0]];
}
}
};

View File

@ -6,10 +6,10 @@ import LocalReducer from '../reducers/local';
import { StoreState } from './type';
import { Timebox } from '~/types';
import { Cage } from '~/types/cage';
import ContactReducer from '../reducers/contact-update';
import S3Reducer from '../reducers/s3-update';
import { GraphReducer } from '../reducers/graph-update';
import { HarkReducer } from '../reducers/hark-update';
import { ContactReducer } from '../reducers/contact-update';
import GroupReducer from '../reducers/group-update';
import LaunchReducer from '../reducers/launch-update';
import ConnectionReducer from '../reducers/connection';
@ -34,7 +34,6 @@ export default class GlobalStore extends BaseStore<StoreState> {
inviteReducer = new InviteReducer();
metadataReducer = new MetadataReducer();
localReducer = new LocalReducer();
contactReducer = new ContactReducer();
s3Reducer = new S3Reducer();
groupReducer = new GroupReducer();
launchReducer = new LaunchReducer();
@ -54,7 +53,7 @@ export default class GlobalStore extends BaseStore<StoreState> {
baseHash: null,
invites: {},
associations: {
contacts: {},
groups: {},
graph: {},
},
groups: {},
@ -97,12 +96,12 @@ export default class GlobalStore extends BaseStore<StoreState> {
this.inviteReducer.reduce(data, this.state);
this.metadataReducer.reduce(data, this.state);
this.localReducer.reduce(data, this.state);
this.contactReducer.reduce(data, this.state);
this.s3Reducer.reduce(data, this.state);
this.groupReducer.reduce(data, this.state);
this.launchReducer.reduce(data, this.state);
this.connReducer.reduce(data, this.state);
GraphReducer(data, this.state);
HarkReducer(data, this.state);
ContactReducer(data, this.state);
}
}

View File

@ -36,7 +36,8 @@ export default class GlobalSubscription extends BaseSubscription<StoreState> {
this.subscribe('/groups', 'group-store');
this.clearQueue();
this.subscribe('/updates', 'contact-store');
// TODO: update to get /updates
this.subscribe('/all', 'contact-store');
this.subscribe('/all', 's3-store');
this.subscribe('/keys', 'graph-store');
this.subscribe('/updates', 'hark-store');