Skip to content

Commit

Permalink
switch from outrecord to String
Browse files Browse the repository at this point in the history
no need for a full record
  • Loading branch information
DougAnderson444 committed Jan 11, 2024
1 parent 650c7f4 commit 8fc1eeb
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 66 deletions.
39 changes: 19 additions & 20 deletions crates/seed-keeper-wit-ui/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ impl Output {
username: self
.username
.as_ref()
.map(|v| v.value.clone())
.map(|v| v.clone())
.unwrap_or_default()
.into(),
password: self
.password
.as_ref()
.map(|v| v.value.clone())
.map(|v| v.clone())
.unwrap_or_default()
.into(),
encrypted: self.encrypted.clone().into(),
Expand Down Expand Up @@ -66,11 +66,11 @@ impl Output {
"{}{}",
self.username
.as_ref()
.map(|v| v.value.clone())
.map(|v| v.clone())
.unwrap_or_default(),
self.password
.as_ref()
.map(|v| v.value.clone())
.map(|v| v.clone())
.unwrap_or_default()
)
}
Expand All @@ -84,7 +84,7 @@ impl StructObject for Output {
"username" => Some(Value::from_struct_object(self.username.clone())),
"password" => Some(Value::from_struct_object(self.password.clone())),
"value" => Some(Value::from(self.concat())),
// self.username.value
// self.username
"count" => Some(Value::from(self.calculate())),
"seed" => match &self.seed {
Some(seed) => Some(Value::from(seed.clone())),
Expand All @@ -104,14 +104,14 @@ impl StructObject for Output {

/// Username captures is the username input value.
#[derive(Debug, Default, Clone)]
pub(crate) struct Username(Option<wurbo_types::Outrecord>);
pub(crate) struct Username(Option<String>);

impl StructObject for Username {
fn get_field(&self, name: &str) -> Option<Value> {
match name {
"value" => Some(Value::from(
// Deref self and use value if is_Some, otherwise use ""
self.as_ref().map(|v| v.value.clone()).unwrap_or_default(),
self.as_ref().map(|v| v.clone()).unwrap_or_default(),
)),
_ => None,
}
Expand All @@ -123,20 +123,20 @@ impl StructObject for Username {
}
}

impl From<&wurbo_types::Outrecord> for Username {
fn from(context: &wurbo_types::Outrecord) -> Self {
impl From<&String> for Username {
fn from(context: &String) -> Self {
Username(Some(context.clone()))
}
}

impl From<Option<wurbo_types::Outrecord>> for Username {
fn from(context: Option<wurbo_types::Outrecord>) -> Self {
impl From<Option<String>> for Username {
fn from(context: Option<String>) -> Self {
Username(context)
}
}

impl Deref for Username {
type Target = Option<wurbo_types::Outrecord>;
type Target = Option<String>;

fn deref(&self) -> &Self::Target {
&self.0
Expand All @@ -147,15 +147,14 @@ impl Deref for Username {
/// We wrap it as a newtype so that we can impl [StructObject] for it
/// We impl [Deref] so we can access the inner of the Rust smart pointer
#[derive(Debug, Default, Clone)]
pub(crate) struct Password(Option<wurbo_types::Outrecord>);
pub(crate) struct Password(Option<String>);

impl StructObject for Password {
// If you add fields to the Outrecord, you'd add them also here below:
fn get_field(&self, name: &str) -> Option<Value> {
match name {
"value" => Some(Value::from(
// Deref self and use value if is_Some, otherwise use ""
self.as_ref().map(|v| v.value.clone()).unwrap_or_default(),
self.as_ref().map(|v| v.clone()).unwrap_or_default(),
)),
_ => None,
}
Expand All @@ -167,20 +166,20 @@ impl StructObject for Password {
}
}

impl From<&wurbo_types::Outrecord> for Password {
fn from(context: &wurbo_types::Outrecord) -> Self {
impl From<&String> for Password {
fn from(context: &String) -> Self {
Password(Some(context.clone()))
}
}

impl From<Option<wurbo_types::Outrecord>> for Password {
fn from(context: Option<wurbo_types::Outrecord>) -> Self {
impl From<Option<String>> for Password {
fn from(context: Option<String>) -> Self {
Password(context)
}
}

impl Deref for Password {
type Target = Option<wurbo_types::Outrecord>;
type Target = Option<String>;

fn deref(&self) -> &Self::Target {
&self.0
Expand Down
12 changes: 4 additions & 8 deletions crates/seed-keeper-wit-ui/wit/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ interface wurbo-types {
placeholder: string
}

record outrecord {
value: string,
}

type encrypted = list<u8>;

record output {
Expand All @@ -29,9 +25,9 @@ interface wurbo-types {
// optional id string: None is intial render, Some for update value
id: option<string>,
// the output dest for the username changes
username: option<outrecord>,
username: option<string>,
// the output dest for the password changes
password: option<outrecord>,
password: option<string>,
// the output dest for the encrypted changes
encrypted: option<encrypted>,
}
Expand All @@ -46,8 +42,8 @@ interface wurbo-types {
// Context variants
variant context {
all-content(content),
username(outrecord),
password(outrecord),
username(string),
password(string),
encrypted(encrypted),
submit
}
Expand Down
12 changes: 4 additions & 8 deletions examples/crates/aggregate-wit-ui/wit/deps/edwards-ui/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ interface wurbo-types {
placeholder: string
}

record outrecord {
value: string,
}

record output {
// the resulting value of the total outputs combined
value: option<string>,
// optional id string: None is intial render, Some for update value
id: option<string>,
// the output dest for the message changes
message: option<outrecord>,
message: option<string>,
// the output dest for the signature changes
signature: option<outrecord>
signature: option<string>
}

// COntent for the entire page
Expand All @@ -42,8 +38,8 @@ interface wurbo-types {
// Context variants
variant context {
all-content(content),
message(outrecord),
submit(outrecord),
message(string),
submit(string),
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ interface wurbo-types {
placeholder: string
}

record outrecord {
value: string,
}

type encrypted = list<u8>;

record output {
Expand All @@ -29,9 +25,9 @@ interface wurbo-types {
// optional id string: None is intial render, Some for update value
id: option<string>,
// the output dest for the username changes
username: option<outrecord>,
username: option<string>,
// the output dest for the password changes
password: option<outrecord>,
password: option<string>,
// the output dest for the encrypted changes
encrypted: option<encrypted>,
}
Expand All @@ -46,8 +42,8 @@ interface wurbo-types {
// Context variants
variant context {
all-content(content),
username(outrecord),
password(outrecord),
username(string),
password(string),
encrypted(encrypted),
submit
}
Expand Down
16 changes: 8 additions & 8 deletions examples/crates/edwards-ui/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ impl StructObject for Output {

/// Message captures is the message input value.
#[derive(Debug, Default, Clone)]
pub(crate) struct Message(Option<wurbo_types::Outrecord>);
pub(crate) struct Message(Option<String>);

impl StructObject for Message {
fn get_field(&self, name: &str) -> Option<Value> {
match name {
"value" => Some(Value::from(
// Deref self and use value if is_Some, otherwise use ""
self.as_ref().map(|v| v.value.clone()).unwrap_or_default(),
self.as_ref().map(|v| v.clone()).unwrap_or_default(),
)),
_ => None,
}
Expand All @@ -50,20 +50,20 @@ impl StructObject for Message {
}
}

impl From<&wurbo_types::Outrecord> for Message {
fn from(context: &wurbo_types::Outrecord) -> Self {
impl From<&String> for Message {
fn from(context: &String) -> Self {
Message(Some(context.clone()))
}
}

impl From<Option<wurbo_types::Outrecord>> for Message {
fn from(context: Option<wurbo_types::Outrecord>) -> Self {
impl From<Option<String>> for Message {
fn from(context: Option<String>) -> Self {
Message(context)
}
}

impl Deref for Message {
type Target = Option<wurbo_types::Outrecord>;
type Target = Option<String>;

fn deref(&self) -> &Self::Target {
&self.0
Expand All @@ -80,7 +80,7 @@ impl Signature {
pub(crate) fn sign(&mut self, msg: &Message) {
let v = msg
.as_ref()
.map(|v| v.value.clone())
.map(|v| v.clone())
.unwrap_or_default()
.into_bytes();
if !v.is_empty() {
Expand Down
12 changes: 4 additions & 8 deletions examples/crates/edwards-ui/wit/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ interface wurbo-types {
placeholder: string
}

record outrecord {
value: string,
}

record output {
// the resulting value of the total outputs combined
value: option<string>,
// optional id string: None is intial render, Some for update value
id: option<string>,
// the output dest for the message changes
message: option<outrecord>,
message: option<string>,
// the output dest for the signature changes
signature: option<outrecord>
signature: option<string>
}

// COntent for the entire page
Expand All @@ -42,8 +38,8 @@ interface wurbo-types {
// Context variants
variant context {
all-content(content),
message(outrecord),
submit(outrecord),
message(string),
submit(string),
}

}
11 changes: 5 additions & 6 deletions examples/sveltekit/src/routes/importables.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ export function buildCodeString(namespace) {
e.preventDefault();
}
let ctx = {
tag: e.target.name,
val: {
value: e.target.value,
}
};
let val = (e.target.dataset.contextValue && e.target.value)
? { ctx: JSON.parse(e.target.dataset.contextValue), value: e.target.value }
: e.target.dataset.contextValue || e.target.value;
let ctx = { tag: e.target.dataset.contextName || e.target.name, val };
let el = e.target.closest('[data-slot]');
if(el) {
Expand Down

0 comments on commit 8fc1eeb

Please sign in to comment.