These are chat archives for pozadi/kefir

Feb 2016
Riley Shaw
Feb 08 2016 17:44
hi :) I'm trying to re-implement one of the examples from the project page (the “Secret combination” challenge)
I'm changing it to regenerate the combination after each successful entry
I'm pretty new to FRP so I've got a few questions. Would someone mind taking a look? (questions in the comments)
(@rpominov, we were talking about this earlier)
Roman Pominov
Feb 08 2016 18:37

Hi, @rileyjshaw. I'll try to answer the questions:

Is it possible to rearrange things so that we don't need a static SECRET_LENGTH defined here?

This should be possible be we'll need a different approach, slidingWindow won't work.

It seems a bit awkward to make this so dependent on the lastCombination stream. Thoughts?

I thought about creating an independent "current secret" stream, but it has to depend on last success stream anyway (since we change secret after success), so probably we'll end up with something similar anyway.

Related: if I wanted to display the combination right away on page load, how would I trigger this?

Well, what we end up with is actually a "current secret" property (when it changes we know that user have entered correctly the previous secret). So since we have "current secret" property, it's easy to display it at any time.

Should this even be a property..?

If we consider it "current secret" property, I think yes.

Roman Pominov
Feb 08 2016 18:50

Is this the "right" way to get the current secret combination?

Not sure. We basically combine two observables that has same common source. I'm still not sure if this is antipattern or not, but I usually try to avoid this. Anyway if you want to combine two observables like this, sampledBy is right tool. We could as well preserve current letters in scan body above, so we would create a stream that emits something like {letters, currentSecret}. Anyway it becomes too complex, and probably need a refactoring and more thinking.

This alerts as soon as the page loads, since secrets has an initial value. We can stop it with .skip(1), but then statusText doesn't update as it should. Where is the best place to stop this initially?

You can add .skip(1) specifically for this side effect e.g., secrets.skip(1).onValue(() => alert('Combination unlocked!'));

Riley Shaw
Feb 08 2016 21:26
Awesome, thanks! Added some of the simpler changes ^ in
I think that creating a an independent "current secret" stream is important here. If we wanted to add a "reset secret" button, for example, we wouldn't want that bound to lastCombination
Riley Shaw
Feb 08 2016 21:32
I'm having trouble wrapping my head around the right way to arrange all of this, though. we could make a combinationCorrect stream, and merge that with a resetButton stream for currentSecret..?
but then lastCombination needs to read currentSecret, so the flow of that is a bit funny
I do think that something like a combinationCorrect stream would be a better candidate for triggering the success alert, though :)
Roman Pominov
Feb 08 2016 21:56
Yeah, if we want a "reset secret" button we need a more independent "current secret" stream. But it gets really tricky indeed: "current secret" will depend on "success" stream in any case, but the "success" stream needs to depend on "current secret", so we end up with a cycle here ("current secret" depends on itself)
Roman Pominov
Feb 08 2016 22:03
I think was invented to solve problems like this, among other
Riley Shaw
Feb 08 2016 23:42
Yeah, cycle looks cool! I was hoping to solve this using simple streams though, cycle is a bit more involved...
I started work on the correctCombination idea here, but obviously the circular stream issue is still breaking it. Let me know if you have any ideas!