agocorona / MFlow

(Haskell) Web application server with stateful, type safe user interactions and widget combinators
http://mflowdemo.herokuapp.com
Other
100 stars 12 forks source link

AJAX - genNewId produces duplicates #48

Closed BartAdv closed 9 years ago

BartAdv commented 10 years ago

Grid demo again: just add more than one row and check produced names - they are duplicated across the AJAX call.

Submitting the form seems to 'update' (for a lack of better word as I do not know the internals very well) the sequence and after that, the names generated are OK (but again, only for first ajax call).

agocorona commented 10 years ago

I have to take a look . I don´t quite remember well how they work. The were the first I did, before developping. autorefresh and update, that were more general .

I will try to remake them using autorefresh-update

2014-07-28 14:38 GMT+02:00 Bartosz notifications@github.com:

Grid demo again: just add more than one row and check produced names - they are duplicated across the AJAX call.

Submitting the form seems to 'update' (for a lack of better word as I do not know the internals very well) the sequence and after that, the names generated are OK (but again, only for first ajax call).

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48.

Alberto.

agocorona commented 10 years ago

DO you mean the produced name attrributes of the fields? I see that they are different....

2014-07-28 14:38 GMT+02:00 Bartosz notifications@github.com:

Grid demo again: just add more than one row and check produced names - they are duplicated across the AJAX call.

Submitting the form seems to 'update' (for a lack of better word as I do not know the internals very well) the sequence and after that, the names generated are OK (but again, only for first ajax call).

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48.

Alberto.

BartAdv commented 10 years ago

Now when I checked it on heroku demo, it's correct. But I'm running Grid demo in ALONE mode, maybe this is the cause?

On Tue, Jul 29, 2014 at 11:30 AM, agocorona notifications@github.com wrote:

DO you mean the produced name attrributes of the fields? I see that they are different....

2014-07-28 14:38 GMT+02:00 Bartosz notifications@github.com:

Grid demo again: just add more than one row and check produced names - they are duplicated across the AJAX call.

Submitting the form seems to 'update' (for a lack of better word as I do not know the internals very well) the sequence and after that, the names generated are OK (but again, only for first ajax call).

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48.

Alberto.

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-50454232.

agocorona commented 10 years ago

I don´t know. I have updated the demo with a solution to the loaded scripts bug that you reported...May be because that.

2014-07-29 11:36 GMT+02:00 Bartosz notifications@github.com:

Now when I checked it on heroku demo, it's correct. But I'm running Grid demo in ALONE mode, maybe this is the cause?

On Tue, Jul 29, 2014 at 11:30 AM, agocorona notifications@github.com wrote:

DO you mean the produced name attrributes of the fields? I see that they are different....

2014-07-28 14:38 GMT+02:00 Bartosz notifications@github.com:

Grid demo again: just add more than one row and check produced names

they are duplicated across the AJAX call.

Submitting the form seems to 'update' (for a lack of better word as I do not know the internals very well) the sequence and after that, the names generated are OK (but again, only for first ajax call).

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48.

Alberto.

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-50454232.

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-50455048.

Alberto.

BartAdv commented 10 years ago

In #47 you've mentioned the widgets are cached? Why is that? It seems that this is the reason of this issue (though I still have no idea why it works on heroku)

agocorona commented 10 years ago

Do you have the issue still? get the last version. It should not happen. The caching of the widgets just makes the errors to be treated silently, no red message appear, but the behaviour is correct.

I tried not to cache the widgets, but that implies a lot of other changes. That is a lesser bug that I will correct later.

2014-08-07 9:48 GMT+02:00 Bartosz notifications@github.com:

In #47 https://github.com/agocorona/MFlow/issues/47 you've mentioned the widgets are cached? Why is that? It seems that this is the reason of this issue (though I still have no idea why it works on heroku)

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-51441221.

Alberto.

BartAdv commented 10 years ago

Yup, but it looks really strange:

setEdited id ws= do
    Medit stored <- trace "setEdited" $ getSessionData `onNothing` return (Medit (M.empty))
    let stored'= trace "wooot" $ M.insert id ws stored
    setSessionData . Medit $ stored'

Trace:

setEdited

It seems to not evaluate stored', hence the edited widget never gets updated and every time I add subwidget it starts from scratch...

agocorona commented 10 years ago

I ran it alone and the "name" identifiers of the form fields are different. Maybe you are referring to something different than what I understand sorry....

2014-08-07 12:16 GMT+02:00 Bartosz notifications@github.com:

Yup, but it looks really strange:

setEdited id ws= do Medit stored <- trace "setEdited" $ getSessionData onNothing return (Medit (M.empty)) let stored'= trace "wooot" $ M.insert id ws stored setSessionData . Medit $ stored'

Trace:

setEdited

It seem to not evaluate stored', hence the edited widget never gets updated and every time I add subwidget it starts from scratch...

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-51454027.

Alberto.

BartAdv commented 10 years ago

Yup, names within row are unique, but they are repeated with each added row.

(My previous comment was wrong, got tricked by laziness, but still, I am getting empty widgets array from getEdited on each modifyWidget call.

agocorona commented 10 years ago

I see then different.... I suppose that you have the same version of Widgets.hs. How I can reproduce it?

2014-08-07 13:19 GMT+02:00 Bartosz notifications@github.com:

Yup, names within row are unique, but they are repeated with each added row.

(My previous comment was wrong, got tricked by laziness, but still, I am getting empty widgets array from getEdited on each modifyWidget call.

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-51459125.

Alberto.

BartAdv commented 10 years ago

Damn, I don't know.

Tell me one thing - modify modifyWidget function as following:

modifyWidget selector modifier  w = View $ do
     ws <- trace ("ws <- getEdited " ++ (show selector)) $ getEdited selector
     let n = trace ("length ws = " ++ (show $ length ws)) $ length (ws `asTypeOf` [w])
     let key= "widget"++ show selector ++  show n ++ show (typeOf $ typ w)
     let cw =  wcached key 0  w
     trace "add" $ addEdited selector (key,cw)
     FormElm form _ <-  runView cw
     let elem=  toByteString   form
     return . FormElm mempty . Just $   selector <> "." <> modifier <>"('" <> elem <> "');"
     where
     typ :: View v m a -> a
     typ = undefined

then start Grid.hs with it, click Add few times. In my case trace looked like follows:

First click:

ws <- getEdited "$('#p0wEditListAddgrid')"
add
length ws = 0

Second click:

add
length ws = 0

Why was the line with ws <- getEdit selector traced only first time?

BartAdv commented 10 years ago

Hm, I've now tested it on GHC 7.6.3 (Windows machine, Haskell Platform 2013) and it works...are you using GHC 7.6.3? If so, are you able to check it on 7.8.3? I am wondering if I have messed something, or whether there is some bug manifesting in newest version...

agocorona commented 10 years ago

The trace is the same. Take into account that modifyWiddget works in the identity monad, so it does not execute what is not necessary...

2014-08-07 15:10 GMT+02:00 Bartosz notifications@github.com:

Hm, I've now tested it on GHC 7.6.3 (Windows machine, Haskell Platform 2013) and it works...are you using GHC 7.6.3? If so, are you able to check it on 7.8.3? I am wondering if I have messed something, or whether there is some bug manifesting in newest version...

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-51468743.

Alberto.

agocorona commented 10 years ago

That is. I can not test it now under 7.8.3

2014-08-07 15:10 GMT+02:00 Bartosz notifications@github.com:

Hm, I've now tested it on GHC 7.6.3 (Windows machine, Haskell Platform 2013) and it works...are you using GHC 7.6.3? If so, are you able to check it on 7.8.3? I am wondering if I have messed something, or whether there is some bug manifesting in newest version...

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-51468743.

Alberto.

BartAdv commented 10 years ago

Damn. I will try to look into this more, but I'm haskell noob and I'm easily tricked even by those traces;)

But to summarize: getEdited returns empty Medit on consecutive invocations of modifyWidget.

agocorona commented 10 years ago

No wait. under 7.6.3 the trace is such:

ws <- getEdited "$('#p0wEditListAddgrid')" add length ws = 0 add length ws = 1

So it is a problem that appears with the 7.8 version.

2014-08-07 15:25 GMT+02:00 Bartosz notifications@github.com:

Damn. I will try to look into this more, but I'm haskell noob and I'm easily tricked even by those traces;)

But to summarize: getEdited returns empty Medit on consecutive invocations of modifyWidget.

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-51470571.

Alberto.

agocorona commented 10 years ago

It has something related with laziness. sure.

2014-08-07 15:47 GMT+02:00 Alberto G. Corona agocorona@gmail.com:

No wait. under 7.6.3 the trace is such:

ws <- getEdited "$('#p0wEditListAddgrid')" add length ws = 0 add length ws = 1

So it is a problem that appears with the 7.8 version.

2014-08-07 15:25 GMT+02:00 Bartosz notifications@github.com:

Damn. I will try to look into this more, but I'm haskell noob and I'm

easily tricked even by those traces;)

But to summarize: getEdited returns empty Medit on consecutive invocations of modifyWidget.

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-51470571.

Alberto.

Alberto.

BartAdv commented 10 years ago

I think it might have something to do with the Typeable instance for Medit - 7.8 brought some changes in this regard and I see for 7.6 you use own instance, whether for 7.8 you derive it automatically.

BartAdv commented 10 years ago

A-ha! In your manually derived instance you don't encode the monad it operates in. And it seems to me that getEdited result is in Identity monad, whether wcached result is in m monad. Now I am not that knowledgeable, but could it make those two representations different under the automatically-derived by 7.8 instance of Typeable (thus effectively session stores at different key it then later tries to read)?

BartAdv commented 10 years ago

Yes, it was that. Checked by changing the Identity to m in all related functions. Now a question - why those widgets were in Identity monad in the first place?

agocorona commented 10 years ago

The reason is because wcached only cache widgets in the identity monad. How did you use other monad?

2014-08-08 11:49 GMT+02:00 Bartosz notifications@github.com:

Yes, it was that. Checked by changing the Identity to m in all related functions. Now a question - why those widgets were in Identity monad in the first place?

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-51582688.

Alberto.

BartAdv commented 10 years ago

I just altered the type definitions from ...View Identity a... to ...View m a.... for those related functions (modifyWidget and so on, including wcache), but I only checked whether it works with regards to this issue, no idea if it didn't break something else in wcache...

agocorona commented 10 years ago

I think that the problen can be solved by changing in modifywidget

    wcached  widget

by

   pageFlow index widget

So the widgets are no cached and the identfiers do not collide

2014-08-08 14:28 GMT+02:00 Bartosz notifications@github.com:

I just altered the type definitions from ...View Identity a... to ...View m a.... for those related functions (modifyWidget and so on, including wcache), but I only checked whether it works with regards to this issue, no idea if it didn't break something else in wcache...

— Reply to this email directly or view it on GitHub https://github.com/agocorona/MFlow/issues/48#issuecomment-51594353.

Alberto.