vrac

2021-09-26T03:33:52.013800Z

In Vrac, the implementation will also use "canonical paths" which are paths without any entity reference inside. It's basically a path which you could use in (get-in app-db path)

phronmophobic 2021-09-26T03:36:59.015500Z

so if you have a model where the same logical entity might show up in multiple places, is it the db's job to make sure updates to a logical entity get propagated?

phronmophobic 2021-09-26T03:38:41.016400Z

that's more or less what I've been thinking, but I haven't found a db with the right API

2021-09-26T03:40:01.018300Z

By "same logical entity in multiple place", you mean multiple copies of the same data, or multiple references to the same data?

phronmophobic 2021-09-26T03:42:15.019100Z

I probably phrased it poorly. The UI typically works based off the denormalized data from a query and it's probably stored in a normalized form

phronmophobic 2021-09-26T03:43:47.019300Z

I responded before I read your #2 from above. I think follow. Is it correct to say that a schema for the data model will be required so that you can tell whether a reference is an entity reference?

2021-09-26T03:47:10.019500Z

I am thinking of 2 different ways to make it work: 1. Make the user list all the keys which will always point to entities, a.k.a. "tagged relations" 2. Use a special data type for representing a reference to an entity. <-- that the approach which I am using in my PoC.

2021-09-26T03:47:55.019700Z

The solution 2. avoids having to specify a schema manually.

2021-09-26T03:50:22.020200Z

oh wait ... I am not sure if I did it that way ... I kind of forgot already.

2021-09-26T03:53:22.020700Z

The Id type acts as an id and a reference at the same time, depending on where it is used.

phronmophobic 2021-09-26T03:54:06.020900Z

right, but it doesn't seem like it would uncommon to need to refer to a property of an entity

phronmophobic 2021-09-26T03:54:45.021100Z

like if you have a checkbox, it could be toggling the :todo/complete? property of a todo item and you would need a reference to that property for the checkbox

2021-09-26T03:55:10.021300Z

It would be referenced via its path in the db, something like [:entities (Id. xxx) :todo/complete?]

phronmophobic 2021-09-26T03:57:07.021600Z

oh, so the component would at some point need to do (get some-entity (Id. entity-id))

2021-09-26T03:58:09.021800Z

Not explicitly (not visible for the user), but the implementation, yes.

phronmophobic 2021-09-26T03:58:49.022Z

> Not explicitly (not visible for the user), but the implementation, yes. I'm not sure I follow

2021-09-26T04:00:26.022200Z

I just mean "yes" 🙂

phronmophobic 2021-09-26T04:01:15.022400Z

yea, if you don't have entities, the key-path works great. It's still unclear to me what the best approach is for handling a data model with entities: • require a schema • components required to know which keys are references • try to support both • something else

2021-09-26T04:04:39.022600Z

In my case, I have entities, no schema, and a special data type to represent references.

phronmophobic 2021-09-26T04:05:08.022800Z

isn't that a form of "components required to know which keys are references"

phronmophobic 2021-09-26T04:05:28.023Z

not that it's a bad thing

phronmophobic 2021-09-26T04:06:01.023200Z

just trying to see what trade-off others are trying and how they feel

2021-09-26T04:06:45.023400Z

> isn't that a form of "components required to know which keys are references" It's not. The component doesn't know anything. The only thing he knows is to follow a path.

phronmophobic 2021-09-26T04:07:19.023700Z

so where does the special reference type get inserted?

2021-09-26T04:07:48.023900Z

They are not in the path. They are in the data pointed by the path.

phronmophobic 2021-09-26T04:08:14.024100Z

so it's in the db?

2021-09-26T04:08:28.024300Z

Yes, and it's totally dynamic

phronmophobic 2021-09-26T04:09:38.024500Z

what's the difference between that and having a schema?

2021-09-26T04:10:41.024700Z

schemas are static vs. data driven is dynamic

2021-09-26T04:11:05.024900Z

For the user, no schema might mean less work.

2021-09-26T04:12:04.025100Z

Both approach can be supported by the framework, I think.

phronmophobic 2021-09-26T04:12:18.025300Z

I could see that working for an existing reference

phronmophobic 2021-09-26T04:12:27.025500Z

how would a new reference be added?

2021-09-26T04:12:37.025700Z

The only part which would need to change would be the function which follows a path to retrieve some data.

phronmophobic 2021-09-26T04:13:18.025900Z

for example, you have list of todo-items and each todo item is a reference. when you add a new todo, it's the "effect handler"'s job to create the reference?

2021-09-26T04:13:45.026100Z

> how would a new reference be added? with-id is a function which turns an hashmap into an entity. https://github.com/green-coder/vrac-simple-sample/blob/master/src/vrac/reframe.cljc#L8-L9

2021-09-26T04:14:52.026400Z

from that entity, you can get a reference to it using (:vrac.db/id my-entity)

2021-09-26T04:15:27.026600Z

Let's move the discussion back to the channel

👍 1
phronmophobic 2021-09-26T03:40:26.018700Z

the main issue is illustrated when you have a dynamic component like a tabbed pane. The selected tab is part of the data and you don't know what data you need to show until you've already queried a subset of the data (ie. each tab will have different data and you don't know which data will be needed for the current render until you know which tab is selected)

phronmophobic 2021-09-26T04:16:14.028Z

so all the effect handlers would need to know which keys are references?

2021-09-26T04:20:13.028400Z

The effect handlers contains the logic of how to change the app-db. When we are not using a schema, the code in the handler also have to know when to use a reference instead of just the data.

phronmophobic 2021-09-26T04:25:01.028600Z

I'm still not sure which options I like best. One thing I've noticed is that it's really nice to have an entity-less data model for testing components in isolation, but you usually want an actual db when integrating a full UI. Having generic effect handlers can help.

phronmophobic 2021-09-26T04:25:36.028800Z

There's also generic components like date* pickers, and list views that ideally shouldn't care

2021-09-26T04:39:56.029100Z

Reusable & generic components like a date picker or would normally not dispatch their own events, they would dispatch events provided by their parent.

phronmophobic 2021-09-26T04:41:59.029300Z

well, the event system in membrane works different than what you're probably used to and no one is dispatching events, but generic components like date pickers do have default handlers

2021-09-26T04:48:03.029900Z

in that case, you can have a schema where the user provides a list of qualified keywords which will always refer to entities.

2021-09-26T04:53:00.030100Z

But that won't solve all your problems, if you default handler have to dissoc data and does not know if the data is just fields in an entity or the entity itself.

phronmophobic 2021-09-26T04:55:03.030300Z

why wouldn't the schema handle that?

2021-09-26T04:57:28.030500Z

When working on Clojure values, you can just dissoc. On a db it's different, you need to say if you delete a link to an entity or if you also want to delete the entity. The schema won't answer this question. If the code in the default handler of your date picker answer this question, it means it is aware of where the entities are.

2021-09-26T04:59:01.030700Z

One solution would be that it answers that question, regardless of the kind of data it deals with. In other word, it would say something like dissoc or dissoc-delete for the operations to be done on the data.

phronmophobic 2021-09-26T05:00:45.031Z

right, if you write* the code using that operation, it would work in either context

phronmophobic 2021-09-26T05:00:56.031200Z

in the non-entity db context, it would just be a dissoc

2021-09-26T05:01:24.031400Z

Yes.

2021-09-26T05:01:43.031700Z

Now I remember that I run into that in April and I forgot.

2021-09-26T04:17:03.028200Z

> For example, you have list of todo-items and each todo item is a reference. when you add a new todo, it's the "effect handler"'s job to create the reference? Yes

👍 1
2021-09-26T05:12:23.033400Z

I might add support for a schema (i.e. the user lists the keyword relations pointing to entities) in Vrac, for the users who need it.

2021-09-26T07:28:49.035700Z

@smith.adriane inside:

(defui counter [{:keys [num]}]
  (horizontal-layout
   (on :mouse-down (fn [[mouse-x mouse-y]]
                     [[::counter-increment $num]])
       (ui/button "more!"))
   (ui/label num)))
If I understand correctly, the view passes the reference $num to the event. Does it mean that the view has to know when to pass the reference vs. pass the value?

phronmophobic 2021-09-26T07:30:28.036200Z

it passes both, the defui macro takes care of passing the extra reference info

phronmophobic 2021-09-26T07:32:07.037900Z

it's a bit of an implementation detail, but every function defined using defui has a special key in it's meta data. the defui macro will look at every function call within the body and automatically include the extra info when calling a function that has the special meta data

phronmophobic 2021-09-26T07:33:09.038800Z

and to pass the extra info, every defui is required to except a single map as its argument

phronmophobic 2021-09-26T07:39:03.039600Z

It was initially meant to be a temporary experiment, but it seems to work surprisingly well in practice

2021-09-26T07:42:36.040800Z

What I mean is: does the user sometime passes num and sometimes passes $num ?

phronmophobic 2021-09-26T07:43:39.042600Z

you mean when calling counter or for effects?

phronmophobic 2021-09-26T07:43:58.043200Z

when calling counter, the user will only ever pass num and $num will be passed implicitly

2021-09-26T07:44:03.043500Z

when creating the effect

phronmophobic 2021-09-26T07:44:14.043900Z

for effects, it will depend

2021-09-26T07:44:52.044900Z

In Vrac, the user would types num all the time, it means passing the reference. The effect handler would be the one to know if it needs the reference or the value.

phronmophobic 2021-09-26T07:46:18.046100Z

you can always get the value from the reference, but not always the other way around

2021-09-26T07:46:19.046200Z

It means that the view does not have to know how the effect handler works

2021-09-26T07:46:33.046400Z

Yes, exactly.

phronmophobic 2021-09-26T07:48:28.047800Z

that's something I would have to think more about. The effect is supposed to reflect the intent of the user. I'm not sure whether describing the intent of the user should differentiate between a reference or the value

phronmophobic 2021-09-26T07:49:14.048100Z

and some arguments are clearly not values references

phronmophobic 2021-09-26T07:49:55.048500Z

that's an interesting point though

phronmophobic 2021-09-26T07:51:32.049200Z

when you implement an effect, do you say which args are values vs refs? can you get both?

phronmophobic 2021-09-26T08:01:29.054200Z

for an intent like [:toggle $bool], it doesn't make sense unless $bool is a reference. for an intent like [:add-to-counter $counter 42], the argument 42 is a literal and no reference exists. I'm trying to think of an example where the difference between a reference or a value would be an implementation detail.

phronmophobic 2021-09-26T08:02:12.054600Z

it's also getting a little late here, so my 🧠 might not be working 100%

2021-09-26T08:13:41.058Z

I have the same goal of trying to deduct which one to use, based on how the effect handler is implemented. I am not sure if it is always possible to deduct it. In the worst case, the user can explicitely write something like (ref counter) when he wants to use the reference inside the effect handler. That's an area which will need clarification in Vrac.

2021-09-26T08:15:20.060100Z

In this simple case, color is a reference and new-color ... it depends what it is, it could be a ref or a value.

2021-09-26T08:16:12.061200Z

new-color is a value, I think

phronmophobic 2021-09-26T08:16:27.061500Z

I guess the question I was trying to ask is if the reference/value difference should be specified by the effect itself and not the implementation. The benefit of specifying it as part of the effect is that you can catch errors earlier

phronmophobic 2021-09-26T08:16:48.062Z

since passing a value when a ref is required is an error

phronmophobic 2021-09-26T08:18:19.063700Z

additionally, I like the idea of being able to provide different implementations for effects depending on the context (eg. testing, debugging, different uses cases, etc)

phronmophobic 2021-09-26T08:18:54.064400Z

so having ref vs value as part of the effect definition might be helpful (or hurtful)

2021-09-26T08:22:08.064900Z

> since passing a value when a ref is required is an error but passing a ref all the time means no error 🙂

phronmophobic 2021-09-26T08:26:14.065400Z

but you can't: [:add-to-counter $counter 42]. 42 is not referencable

2021-09-26T08:27:33.065700Z

ah, you are right