contacts: end to end tested apis with working reducers

This commit is contained in:
Logan Allen 2019-12-04 14:41:44 -08:00
parent 082a44a7f8
commit ed481d89a5
9 changed files with 99 additions and 78470 deletions

View File

@ -92,8 +92,8 @@
==
::
%delete
:~ (group-poke [%bundle path.act])
(contact-poke [%create path.act])
:~ (group-poke [%unbundle path.act])
(contact-poke [%delete path.act])
==
::
%add

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
|%
++ nu :: parse number as hex
|= jon/json
?> ?=({$n *} jon)
?> ?=({$s *} jon)
(rash p.jon hex)
::
++ rolodex-to-json
@ -15,7 +15,7 @@
|= [pax=^path =contacts]
^- [cord json]
:- (spat pax)
(pairs [%contacts (contacts-to-json contacts)]~)
(contacts-to-json contacts)
::
++ contacts-to-json
|= con=contacts
@ -45,6 +45,8 @@
++ edit-to-json
|= edit=edit-field
^- json
=, enjs:format
%+ frond -.edit
?- -.edit
%nickname s+nickname.edit
%email s+email.edit

View File

@ -0,0 +1,10 @@
/+ *contact-json
|_ act=contact-action
++ grab
|%
++ noun contact-action
++ json
|= jon=^json
(json-to-action jon)
--
--

View File

@ -0,0 +1,14 @@
/+ *contact-json
|_ rolo=rolodex
::
++ grow
|%
++ json (rolodex-to-json rolo)
--
::
++ grab
|%
++ noun rolodex
--
::
--

View File

@ -0,0 +1,13 @@
/+ *contact-json
|_ upd=contact-update
++ grow
|%
++ json (update-to-json upd)
--
::
++ grab
|%
++ noun contact-update
--
::
--

View File

@ -9,18 +9,16 @@ class UrbitApi {
setAuthTokens(authTokens) {
this.authTokens = authTokens;
this.bindPaths = [];
this.groups = {
add: this.groupAdd.bind(this),
remove: this.groupRemove.bind(this)
};
this.contacts = {
edit: this.contactEdit.bind(this)
};
this.contactView = {
create: this.contactCreate.bind(this),
delete: this.contactDelete.bind(this),
add: this.contactAdd.bind(this),
remove: this.contactRemove.bind(this),
edit: this.contactEdit.bind(this)
};
this.invite = {
@ -63,36 +61,20 @@ class UrbitApi {
});
}
groupsAction(data) {
this.action("group-store", "group-action", data);
}
groupAdd(members, path) {
this.groupsAction({
add: {
members, path
}
});
}
groupRemove(members, path) {
this.groupsAction({
remove: {
members, path
}
});
contactViewAction(data) {
this.action("contact-view", "json", data);
}
contactAction(data) {
this.action("contact-store", "json", data);
this.action("contact-store", "contact-action", data);
}
contactCreate(path) {
this.contactAction({ create: { path }});
this.contactViewAction({ create: { path }});
}
contactDelete(path) {
this.contactAction({ delete: { path }});
this.contactViewAction({ delete: { path }});
}
contactAdd(path, ship, contact = {
@ -101,10 +83,10 @@ class UrbitApi {
phone: '',
website: '',
notes: '',
color: '0x000000',
color: '0',
avatar: null
}) {
this.contactAction({
this.contactViewAction({
add: {
path, ship, contact
}
@ -112,7 +94,7 @@ class UrbitApi {
}
contactRemove(path, ship) {
this.contactAction({
this.contactViewAction({
remove: {
path, ship
}
@ -126,7 +108,7 @@ class UrbitApi {
{phone: ''}
{website: ''}
{notes: ''}
{color: '0xfff'}
{color: 'fff'} // with no 0x prefix
{avatar: null}
{avatar: {p: length, q: bytestream}}
*/

View File

@ -7,7 +7,9 @@ export class ContactUpdateReducer {
if (data) {
this.create(data, state);
this.delete(data, state);
this.delete(data, state);
this.add(data, state);
this.remove(data, state);
this.edit(data, state);
}
}
@ -24,6 +26,43 @@ export class ContactUpdateReducer {
delete state.contacts[data.path];
}
}
add(json, state) {
let data = _.get(json, 'add', false);
if (
data &&
(data.path in state.contacts)
) {
state.contacts[data.path][data.ship] = data.contact;
}
}
remove(json, state) {
let data = _.get(json, 'remove', false);
if (
data &&
(data.path in state.contacts) &&
(data.ship in state.contacts[data.path])
) {
delete state.contacts[data.path][data.ship];
}
}
edit(json, state) {
let data = _.get(json, 'edit', false);
if (
data &&
(data.path in state.contacts) &&
(data.ship in state.contacts[data.path])
) {
let edit = Object.keys(data['edit-field']);
if (edit.length !== 1) {
return;
}
state.contacts[data.path][data.ship][edit[0]] =
data['edit-field'][edit[0]];
}
}
}