Placeholder Image

字幕列表 影片播放

  • I'm there for the night theater and get happened.

  • Almost everything else.

  • Ah, I'm gonna talk about state machines, meat cooks who knows its machines here.

  • All right, so, yeah, I know that you're all this.

  • You gotta step.

  • Machines are only good things, right?

  • It has been around for decades on end.

  • Now we're bringing this old stuff in tow.

  • React cooks who just Just probably a few months ago, released on the stable fashion off.

  • So, yeah, I have a family have two kids, and I'm living in Singapore, working as an indifferent working at me, different as front and stuff.

  • Previously, I was a big n developer, but I just moved to front end for 1.5 years.

  • And I love freak, and it took Well, look here.

  • Great.

  • Okay.

  • What?

  • The stock is, uh, here I am goingto give you a very brief introduction to step machines.

  • So far, you who would just born yesterday?

  • Who?

  • Just who never heard off those machines.

  • Probably unit toe, get some a basic concept of it, and then I'm gonna walk you through to Ah, my personal journey.

  • When I was working on a feature in In German.

  • Uh, but the journey is too long.

  • Toe Graham up in 30 minutes, right.

  • That's why I graham I cut it down and I simply fight those things.

  • What you're seeing here is not the real thing that I built.

  • But it's just a simulation off off my journey at the time, so and since it's a good journey, so there will be a lot off.

  • So, luckily, this is my This is the first time in the morning.

  • So I hope we are fresh, enoughto digested more good this morning.

  • And what the stock is not this.

  • This is not an introduction to a real cooks.

  • So I'm not gonna introduce you to any consequence cooks.

  • And it's not also down the state machines.

  • One set because it has a lot of concepts.

  • We if you talk about it, certainly it will take a few days.

  • So what?

  • It's technicians?

  • Well, when I'm mentioning that machines, I am referring to this finance technicians, which is on Wikipedia.

  • Yeah, it's like this the definition and we have some states and this so and why are we bringing this old stuff in tow, For instance, because you're released that machines are only used in critical systems in alien guest company in Nassau for building the rougher to send to Mars because, ah, they can afford to have editor on the back.

  • In production like us, we can afford it, right?

  • We can afford a bag in protection, and we can immediately Ah, push.

  • I'm caught and deploy it.

  • But that's not the case for them.

  • They can't just push a kowtow marsh, right?

  • Because it take months to get there.

  • So, uh, but why?

  • Why bringing this this complicated stuff in the front end?

  • Uh, there are a lot off.

  • There are a lot off, uh, explanations.

  • We just explained by the creator off extra in this talk so you can just go through the accommodation and take a look.

  • Why is this important?

  • But the one of the idea that I am getting so out this, uh, because it provides a common language for dissenters and developers.

  • So let me explain it.

  • Anybody ever get this kind of float from dissenters are?

  • Yep.

  • 123 Okay.

  • So are we the only ones doing the complex stuff?

  • Ah, so I got I have a pit in in our product in Japan, which is basically a calendar.

  • So this calendar, you know, on interaction in a calendar is a lot.

  • Right there could be creating your staff or feeling the staff or feeling the list off items in calendar on.

  • Since we are stop, we do it lean.

  • So instead of having all requirements given up at the first place, we we just get the requirements gradually one by one.

  • So initially I got on leave everyone off this diagram, but then I'm the next minute I get another one, and then I get another one.

  • Then this diagram getting more and more complex, and it's it's getting harder for me to understand my coat and really might go to this taker.

  • But luckily, uh, I'm getting Beach Bay this idea so somebody s Oh, when I watch the talk, Yeah, he said that that machine provide a common language for the centers and developers, and I thought it is quite make sense because we're having this, uh, by using some machines, we can actually coat in a way that the diagram is presented to us, and I will show you later that we can do my sources.

  • So my problem.

  • Ah, at the time was the complex I flows that I get it.

  • The wires multiple states.

  • Uh, but he states Europe, I mean, states in react so I can be in hooks on it can be in the last components with It's basically the REAC states and multiple states are generally the implicit, which means Well, we believe some, let's say we have three states.

  • Uh, we have a combination of three states on the company, right?

  • And then we have forced this.

  • We have permission forthis.

  • Imagine if your eyes too complex, we can get this ditz exploded and it's getting harder to minute the state's inspected.

  • Yeah, So those implicit states, uh, for me, it's harder to reason about that's why Buck Skip showing up on production due to this invisible state.

  • So I thought that I covered all the states, but apparently there's some other combination off states that is not covered yet, and it's appearing in production.

  • So yeah, let's try using state machines to solve this problem.

  • So my hypothesis is ah, By using step machines, we can make our state's visible, which means if we have any invisible states means no hidden box anymore.

  • All right, so let's hope it turns out that way.

  • You know what?

  • So I thought it would be a lot of a lot of good.

  • We're starting to jump into coat.

  • I will give you a brief streams interaction through the exit.

  • Maybe so.

  • This is a simple taco Machine example.

  • So I'm just importing a machine function from extent, and I passed down.

  • Ah, conflagration object to the machine.

  • This confidential reject configuration object should contain at least the first is the initial state.

  • So we instead that it's, uh, initially on when it started and then all the available states.

  • So in this case, I have inactive state, and then I have active still as well.

  • And within those states, we can define state transitions, so we just a wayto move difference between states.

  • So, in this case, on toggle events, we moved to active state and on and from that lifted on, totally friends to do the same event.

  • We moved to the active state s.

  • So this is the bare minimum off station.

  • So we can try to copy this line, and we can visualize it from the coat.

  • Yep.

  • You're this So Now we get our coats with allies like this.

  • So it looks like the diagram that I showed you before the diagram that I that we got from the designers.

  • It seems a bit overkill, right?

  • When yoga stuff, what can be more complex in this?

  • What?

  • Why do we need this 7 20 just for throwing stuff?

  • But we will get to it soon.

  • So let's start the journey.

  • Ah, here.

  • I'm gonna walk you through my journey and I'm gonna split them step by step.

  • So it's step contests off first, the conference, you know, implementation off.

  • If using hoops and then next we'll get into this state mission definition and then next we will integrate that state machine into our.

  • So for the first, let's say imagine this.

  • We're doing it in sprints and these hours for spring.

  • So the first feature is simple.

  • It's just toggle the motor visibility, which I see.

  • I have bottom and I click.

  • And most of us and I close and it goes is its simplicity.

  • This hour bear, uh, component, which uses a button and a model.

  • And I feel nothing here yet.

  • So for tracking the visibility step, usually we use Houston on, then we this initiate they're still with force.

  • An on button click we sedated through on close model.

  • Click.

  • You said it.

  • Plus So this hour implementation it seems simple, right?

  • Why do innit?

  • CET machines.

  • Uh, but let's try doing this simple thing is exhibitions.

  • So I just I just had an idea here.

  • So it's easier for us to understand this a machine for this case.

  • So we have an invisible state as an easier, and then we, uh, put on open even so that it can go toe.

  • Is it busted?

  • And this was supposed it has a close event, the invisible state.

  • So this is our simple machine, which looks like our taco machine before and when we saw like that it has a similar thing.

  • The different.

  • The only difference is that we have different events.

  • The digger.

  • So by having given events, there is no way for this state.

  • Let's they were invisible state, and we send close event people do nothing because there's no cross even on this date.

  • So that's what makes it ah content.

  • We cannot go to any other state which is not defined here.

  • So Let's integrate.

  • That's a machine into our This is the same bourbon up, but I just imported by the stuff Use machines Year is, ah, cooked area custom hooks, which is written in extent.

  • And you can look at the expression on the recommendation I wouldn't work it through.

  • And this custom hooks except first the machine itself, the machine definition that we just did and then it, except some options, which is one of them is the left, which means that we can be back.

  • Our, uh, our our in deducts difficult.

  • And we accept we get the concert and the scent even send a function toe send.

  • Even so, for opening the model just simply sent an open even And for crossing the model to simply sound close even.

  • And here, uh, toe determined it, whether the motor is sure or not.

  • Instead, off missing physical state before we pass down the current state and the fella off the current state.

  • And if this is visible, then we display the motor.

  • Yeah, this is it.

  • And we still have the same working with our company.

  • But the difference is we can track it down in you duck.

  • So we have open even here, standing still visible.

  • And we have close even here.

  • Changing Stefan.

  • Okay, get some simple.

  • But now let's go to the spirit and the spirit toe government.

  • We just We have differences between you and edit screens.

  • But then our motor was just no content.

  • Right?

  • But now it is a content, and it has Ah, I didn't buy them when I s Oh, it's feeling the thing here.

  • And then when you click that it it is editing that thing and it triggered something.

  • So that's the second gentleman.

  • This is our old court in conference, you know, hooks.

  • We have to add another state because we're talking another thing right here.

  • So we just add anything state and then direct the state's value that we're passing down to the model.

  • So, uh, we are pressing down this, You and Dad, it's that fellow based on those two states before the feasible and anything.

  • If it is busy, building isn't everything in this view.

  • And, yeah, something like this.

  • And that's for this.

  • We're getting busted.

  • And now for a change in the state, we should probably get this the events off clicking or some are off clicking this bettors, though, setting the states.

  • So right here we we said anything to force when we want.

  • When we question the motor so it gets to the initial state and then on edit button, we just set it the truth.

  • So that's our implementation.

  • It's still many deeper so far.

  • So why don't we?

  • But why we better is writing machines, but we do it some useful stuff sometimes.

  • So Ah, now it's right.

  • State machines on right here.

  • I'm going to introduce you to a new concept port here.

  • Hi, Rocky Coast.

  • So, uh, here we have a new state, but it's not in is not tumbling off the extinct, But it has to be Children off on existing state because this that is actually inside the visible.

  • Because this that is only access when the motor is pretty boring.

  • And we can just add the state's inside it.

  • So this is called Erica.

  • Cost three State and inside the PC busted.

  • We have fused it, which is an energy off.

  • That and then we can go to the estate, but then from, and it's that we need to go to the parent state right, So there is no the default way When it access to the state, it can only access this.

  • It's sitting.

  • Sit.

  • So how do we access the present state?

  • Luckily, exit profit away toe.

  • Do it by defining an I D on parenting or any any state or anywhere on the machine.

  • And then we can just refer to that idea right this way, putting ah Hoesch in front of it.

  • So this is our state mission definition.

  • Then it looks like this one, if you like it so on Invisible Uh, this invisible, invisible thing is the same thing that we have previously.

  • But then we have two new state inside the physical state.

  • So when we're on few, we can edit it and we're already too conservative.

  • And when we're inside any off this, we can still close the motor.

  • That's how it works.

  • So that's implement this in our state machine.

  • These are profuse one.

  • We need to check the feeling that we're passing through the model because now our PC boasted it's not string.

  • It's not always a string because on fizzy, but we have two interstates, so it will be an object.

  • So we're pressing down that object.

  • So if if that if the state is an object and contents visible and zebra contents interstate then repressed that interstate, otherwise it will be undefined so that that's why this is still fell into our model.

  • So what will be on show when we have some interstate indefensible?

  • They and then for editing, submit defense.

  • It's just simply sending those events.

  • You see the scent function, that's it.

  • And when you try doing this, you get the works and we can also see the ducks.

  • You So now when we were opening this date, Yeah, Now, now we have this visible at it.

  • So when we're close, the value is the fella is invisible and when you open it, if l A is not feasible with few and now it's physically ready.

  • So it's how extended presents in the States.

  • Okay, so far, we're getting with more complicated here now.

  • So ah, on the sprint tree, we had a new feature, uh, to show the create screen when opening widow with empty data.

  • Remember that my case was a calendar.

  • When we click.

  • Did there could be something in it, which is this is our way just this case.

  • But there could be nothing on it, which we didn't have anything to show.

  • Right?

  • So that's why we have to goto immediately.

  • Anything more, which is called great because we're creating something.

  • So we have two cases now and the locomotive that in our conference in elimination, we at another state data, they do that or the thing in the country and we initialize it with an empty.

  • So now it's getting more complicated.

  • Well, we have to incorporate these three states visible editing and data toe and derive a state really from death.

  • Then we have to write these conditional stuffs.

  • This seems a bit still more manageable, but we have to go far away.

  • Forwards so disobeyed the buttons toe have two things Now, Now we can open empty with just the old stuff, and then we can open access, which is we are something we're opening the border and resident their data tohave some point.

  • And here is this an empty street to simplify.

  • And don't forget toe clean up the data when we're crossing the motor or something.

  • So this our implementation.

  • Okay, now it's getting more complex because now all off all this addition.

  • Allergic are scattered everywhere, and it's harder to understand because it's the implicit which that is, this list or on which they actually.

  • So let's try implementing this with machines.

  • And here, here is where, uh, it goes more useful.

  • No.

  • So in this case, we're triggering the same event.

  • We're just opening the motor.

  • So we need a tow.

  • Ah, transition the state from invisible to visible.

  • And here is how we do find the tradition.

  • But there's another way off defining this transition, which is, ah, if I think it is an object so that we can add some more things here.

  • So this actually the same thing with the British one and this another way toe define it as in a raid so that we can get different things so that so now we can start get different states from the same state.

  • We're using the same event.

  • How do we differ between this targeting the Stargate?

  • We do for it using condition.

  • So this condition instead machine is called guard, which means imagine a state is a place and we have guards in front off the in, one off the state in front of the place, like like our gut, which is scanning our attack.

  • So even if somebody is trying to come into the stage without having the property, they wouldn't be allowed to come in.

  • Right?

  • So this, like this is why it got It's called God.

  • So here we are guarding that if the data is zero, if the delivering zero and then we go to this state, otherwise we go toe, we just want So just get that at a great state and that's it.

  • So this our news, visualize attention.

  • We have a new coalition here, so it's the same event but different conditions.

  • With this condition, we go directly to create and the rest of the scene.

  • So when you implement this into the ocean, let's rename the current button and then you know it's open, empty and best don't on object instead of just passing on the string.

  • Now we press on, press on object with type off that string and a popular in it, so don't on empty, and we also need to have another mother button which sends the same event but differently that here, that's it.

  • That's our implementation in our component so it still works the same.

  • I did empty cause to create immediately.

  • Okay, No, we get to the final spring in the storm.

  • We have to show lease screen when you're opening a mortar with multiple data.

  • So imagine that there is a dead where we have multiple things.

  • They're so we don't know yet which want off.

  • You're right, which want to feel like this.

  • So if you have multiple it, which one does show?

  • We don't know.

  • That's why we are displaying a list of them and the user can click on one off the list and we can show the few, and it does the same thing like before.

  • So now it is our boat confident Another step, which is called Index, which represents the index that we are seeing.

  • And I saw it with with minus one.

  • So it's so if we refuse now, when we compare it to other numbers, strange in the positive.

  • So just let's use this Centinela Valley then incorporated index into our new state, which is leased.

  • And don't forget to add another condition because now that this condition is change because of this at new buttons with different data here.

  • No.

  • Forget to reset that index minus one.

  • We need Chris tomorrow.

  • So now it's getting more and more complicated.

  • Well, this is not mind blowing yet because it's the stuff.

  • Or imagine that in production, I have, like, just a pen or step 20.

  • So yes, it blow my mind.

  • So, uh, incident, since we can do it your way we can with the same way that you did before.

  • So it just at another guard and another state go.

  • But then now it's getting harder to read, right?

  • Because then what's the point off using stem mission.

  • If if we still get it hard to read, we can.

  • L iust this date.

  • Sorry, we can't let this guard into a simple string, so it's more edible.

  • So now we have, if empty than this, if single than this and else this.

  • And we defined the skirts in tow, this object in step.

  • So there's the second object that we best of the machine.

  • And it's just naming the condition us as a string and then the final literally state with any actions interacting with.

  • So that's you are used it.

  • We have a new open, even stayed with different conditions, but now it's with a proper name.

  • So if it's empty, then it's going here.

  • It singled and it's going here.

  • If it's nothing that is going to the state which is initialized with this.

  • So yeah, now in this at another button, we're open, uh, even same often even but different data.

  • Now we have multiple data, and inside the motor we have an interaction, toe a few of the details and go back to the least views or were dispersed on the back and you events.

  • That's it.

  • Our position is no more readable, and it's easier to Regis And no, we can inspect this.

  • Yeah, it's working one.

  • All right, so let's compare our previous incrimination the old ways, though the state machine abomination.

  • So we got the machines.

  • We usually used it right?

  • But then, with this machine, we don't use it anymore.

  • We just use use machine and replaced those multiple states before we just single call off the use machine.

  • And we have just two things here.

  • Now this is the state and this the event and now that are having those implicit that sets that costs, which we don't really have any idea what does this, too.

  • Oh, this is doing the same thing, actually, but it's harder to understand.

  • We need to read this court probably two or three more times toe actually understand what's happening on this good.

  • But by using the machines, we can just no, what happened?

  • What's happening on this button?

  • What's happening on this action just by looking at once and now our is more simple And, uh, he's here to understand, but we are told this moving away, the complexity from debt to the state machinery.

  • But the situation is still complex, right?

  • Yes, it's still complex about the difference between desert.

  • We've seen the commercial that said machine and the competent off.

  • The very first implementation is this machine can be visualized easily, So we're using the same fertilizer.

  • We can visualize all the states in a way that that corresponds to the floor that we have that we get from the designers.

  • So this was realization for me.

  • It did uses the cognitive overload.

  • So, based on my experience, the offensive this is now, since all still are feeble, it's easier to test so we can discuss from when from whichever state to go to whichever state.

  • And in fact, I did all the tests.

  • So I'm confident enough with my machine.

  • I am confident that my machine wouldn't break but isn't back three s I had with the test.

  • Apparently not.

  • So it's not completely back free.

  • So the back comes not from ST, but it game from the discrepancies between the state and the rented fuse.

  • So I had the question.

  • But, you know, inside that motor, I'm just so far, we're just passing down the steps of the motor.

  • Right?

  • But what's happening inside the motor is some.

  • It can go wrong over there.

  • So the box is coming from that motor for you.

  • So is that just testing the state?

  • We should also have tested the rendered few, such as?

  • Well, in this case, we should have tested motor off you.

  • So that's why I'm suggesting, uh, asked the consider integration tests.

  • So my lesson, sir, In this journeys, when we're using some machines, it must be descend throughly because it's a complex stuff it so the state machines will just work, but it works as we designed.

  • So if we decided bitterly, then it was and Yes, it's easy.

  • The pesticides, because just disgusting.

  • The straying.

  • Testing the object, right?

  • But don't forget the test, the rendered fuse.

  • And And I did thing that island is Devon super about it.

  • We cannot use still machines everywhere, just like we can use three ducks everywhere.

  • And we cannot get the right step from Rob's anyway.

  • Yeah, so just be mindful that we might not need the machines.

  • Yes, well, so might take away from this.

  • Experience is, let's use that machines sparingly, so use it when you need it, and when you use it, it's only isolate this, that management in tow.

  • Custom hook.

  • So it's easier to understand and the pests and always test your courts.

  • Really, which means testing all the courts, including the few so in the stock very scratched the surface off the machine's concept.

  • There are a lot off, uh, things more machines you can just read out, read upto the except the commendation.

  • A lot of things, even in fact, I didn't I also didn't learn all this stuff there yet, so I just explained what I implemented.

  • So I asked him, also says it's suggesting you to learn at the testing trophy by considered actually actually took his scars.

  • And it seems much more useful Re friend.

  • Some bucks happening in our good now so we can get enough confidence within our coats.

  • So I think that's all.

  • Thank you for your attention.

  • And I you wantto give a special things toe different.

  • Course it, which is the greater off extent Andrada Go boom, boom for his amazing could suffer that I used here, even though it is still in off our version.

  • But it's pretty good, right?

  • I think there's nothing wrong happens so you can access this side in this thing and that's all, Thank you.

I'm there for the night theater and get happened.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

狀態機遇上React Hooks - Zain Fathoni | JSConf.Asia 2019 (State Machines Meet React Hooks - Zain Fathoni | JSConf.Asia 2019)

  • 4 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字