Placeholder Image

字幕表 動画を再生する

  • Hello and welcome to a live stream of done.

  • J s L A.

  • My name is Jason, Laura, and I'm not gonna move my laptop in fear of messing up the h in my connection.

  • But I'm here live with a bunch of people at Code Smith's office and Venice.

  • Say hello.

  • Hey, I'm not alone.

  • All right.

  • Uh, I'm gonna share my screen, eh?

  • Uh huh.

  • And present.

  • All right.

  • Just infinite instead of the extreme.

  • Okay, Um uh, Sahara.

  • And tonight we're gonna learn how to build a tender tender, like a carousel.

  • So this app that you see on the right this evil tender, you might see some faces or some things that you recognize evil characters.

  • Eso We're gonna build this app.

  • It has a like and no button.

  • Um, we can say yes or no on then.

  • It has swiping as well.

  • So if we swipe left, there's this little no intimation that comes up.

  • Or if we swipe right, it'll be the little like And then when we let go, we go to the the next character.

  • Um, So that's what we're gonna build before we get into it.

  • I want to say thank you to our sponsors.

  • So, uh, here here, where we're hosting tonight is folk Smith.

  • You're not familiar with coats?

  • Matt's definitely checking out its midst.

  • Io.

  • They're not a boot camp.

  • They focused on programmers who especially self taught.

  • If you're like me and self taught, and then you wanna kind of up your skills and go to that next level, it's like developing your suffer, engineering your programming, your machine learning skills.

  • That's all things that they focus on.

  • So definitely check out code.

  • Smith thought Io.

  • They have offices obviously here in L.

  • A and then New York and then Oxford University as well.

  • On then, my employer would like to think them eyes.

  • But Toby were jobs fits consulting company.

  • We have a wide variety of plants, from small nonprofits and start ups to Fortune 500 companies that we saw on every sign NBA's with and can't talk about.

  • Um, we build APS for them.

  • We have a team of developers.

  • I'm one of them, uh, and an awesome user experience team.

  • So we tackle design way tackle building applications from both like the design and development, So check out the Toby dot com and that brings me to why we're here today and what I do s I said I'm chasing.

  • I'm part of the 14 that develops a bunch of open source text for Toby That includes can just Andrea steals gas.

  • That's ever so we're gonna use Candy s today.

  • Thio kind of give us the tools to build our application.

  • And Candace is a client side JavaScript framework.

  • It has its roots going back 10 years ago, and a friend were called Java script in D.

  • C.

  • So it's been around a long time, but it makes it really easy from to build is simple web widgets all the way up to scaling to larger applications.

  • And this is how we build absent.

  • But Toby, um, so has three main principles.

  • And make sure that my screen this is large, as it could be.

  • Okay, um so basically, but the core concept of kanji s is you build components and the components is a A tag, a custom element tax.

  • So when you put that tag anywhere in each to Mel that that tank gets upgraded into a custom element or into a component, it's rendered with a view, so you'll see between the tick marks.

  • This is what we call I can stash you who's seen, like handlebars or mustache before?

  • Yeah, OK, so it's a very it's a similar syntax where wherever you have double double curly braces like this, that means that that value is gonna be replaced with something dynamic.

  • So we've got the double curlies and counts.

  • Um, and Can Stash also has a binding syntax for listening to events.

  • Eso this on colon will listen.

  • Thio click events, DoubleClick mass out just any don't event that you can think of, you can put their on.

  • And then when that event happens on the element, then, um then a method fires, then the last part.

  • So that's so, uh, custom elements are with tanks.

  • They're rendered with a view, and then the third part is that's backed by a view model.

  • So of you model is just a model for your view, like you're providing whatever properties and methods that you need in your view.

  • So in this case, we have account property that starts off with an initial value, or it's a fault value of zero, and then we have an increment method so that When the button this clicks, it will call this method and the model on we can put whatever logic we went in there.

  • So in this case, we're just implementing our account on dhe.

  • That's it.

  • This this is how we build, like, simple widgets.

  • This is how we scale up to you entire web applications that are built from these principles that you have custom elements that are components that have a view that are rendered with a view model for all of the properties in actions.

  • That's it.

  • Any any questions, comments before we move on?

  • Yeah.

  • You know, I would do best in this.

  • I love you.

  • Yeah.

  • So, um, view and react and angular and kanji s and number like that, there's Yeah, there's so and so when Toby started 10 years ago, there was no view or angular or emperor or react.

  • So we started developing our own framework.

  • And from there it's grown into what we have today with Kant.

  • Yes.

  • So yeah, yeah.

  • Um, there's other companies that contribute to you kanji s and other frameworks, but were the major contributor.

  • So, um, and white like the maybe a little bit.

  • Yeah, we can definitely get into, like, specific stuff.

  • Like, what are the trade offs?

  • And and, uh, why you would pick?

  • Hopefully from just going through the going through the building and application today, you'll get feels for like, oh, what you like about this framer.

  • Hopefully it's all what you like about this, Rick.

  • Um, cool.

  • Any other questions?

  • No.

  • Okay.

  • Uh, so take your laptops.

  • Everyone's connected to you.

  • The internet.

  • Uh, go ahead and go to candy.

  • It's dot com and on the left hand side, uh, that's candy S e a N J s stuck on, um, And then on the left hand side, you'll see a, uh, a guide slink and then under the recipes section, uh, there's a tinder carousel.

  • When you click on that, you'll end up on this page You can also search for If you're feeling fancy, search for gender, it will come up.

  • Can I have some?

  • When that page in, everyone's on that page.

  • Kenji s dot com and then guides.

  • And then under the recipe section, there's the gender gender carousel.

  • Everyone get Look here.

  • Okay.

  • Yeah, that's great.

  • Yeah, Yeah, were grand.

  • What?

  • Do you have another brother Do you have Firefox, sir?

  • Graham Spaulding?

  • No, Um, we just got here that I couldn't breathe.

  • Yeah, that that maybe if you're able thio a newer version that's like from, or Firefox and go from there.

  • Um, are you just didn't call?

  • It sounds good.

  • Um okay, so basically, how tonight it is gonna work is we're gonna go through all of these steps of building that app that I don't move it a little bit earlier.

  • So we'll, uh, we'll set everyone up, and then we'll go through the steps of, like, showing a current and next profile image, adding the I think it was a heart I can't remember.

  • What is the light button?

  • Yeah, the like button will add the, um, the X note button and make those work will make the like, sliding and tracking mass events work.

  • We'll have the overlays were gonna do those all in in steps, So I'm gonna talk about the problem that we want.

  • Thio tackle the give you everything you need to know to try it out on your own.

  • And then I'm gonna give you guys five or 10 minutes for each step to actually try it.

  • on your own hack away, See if you can get it working, and then we'll go over a solution together.

  • And after that, um, the site has these really handy copy buttons in the upper right of all of the code examples.

  • So don't fret.

  • If you didn't come up with a solution on your own, it's really easy to just, like copy paste and get up to speed.

  • So, uh, go down to the set up section.

  • You can do that from, like, clicking the knave or this snap or just strolling down to the set up section and you'll see an almost completely blank, uh, could pen and click on the edit on coat pin, um, button in the upper right of that so they'll open a good pen.

  • Um, the H e mail of field should be blanked.

  • The CSS We're not gonna worry about Stiles at all.

  • That's just there for us to utilize s.

  • I'm gonna collapse that, um But R j s me jx forget.

  • Right?

  • A lot of gas in here, So, um, we'll we'll expand.

  • Um, school.

  • Everyone have their They're cooked an open.

  • You don't have to sign up for anything just open and pull at it away.

  • Um, cool.

  • So let's go through what?

  • The Java script does its fairly straightforward Who has seen the Yes, six imports in tax before.

  • Who has seen this, Like import?

  • Yeah.

  • So, um, until recently, the best wayto load scripts was with a script tagged and that put something on the window and you start using it, which isn't great for maintain ability or modularity or what have you eso in candy?

  • Yes.

  • You can use the native import statements.

  • This isn't running through like, uh, Web Packers steel dress or any of the other bundlers.

  • It'll load this file and then import this module out of its components is basically all we need to build a candy ass application.

  • Um, so we're gonna we're gonna make heavy use of of components plants.

  • So the first thing that I want to dio is kind of similar to what we had on the home page.

  • I want Thio create a components were going to create an evil, tinder custom elements.

  • And when that is in our reach, Jim Bell, I wanted to render, uh, to render this each time out so you might tell me.

  • Okay, well, I can put that html in there, and then it's done rights.

  • We're gonna want to make this dynamic.

  • We like, right now, the currents and the next it's all hard court.

  • Coat it in there.

  • So that's why we're gonna want to have that as a component in our job description s.

  • So what do we need to know?

  • OK, so we've been through some of this already, so we can use components, and we'll use component that extends.

  • And we'll set evil tender as the excuse me as the tab.

  • So when we have brackets evil tender in our HTML, the component will take over on.

  • And then, in our view, we want everything up here.

  • So I would make heavy use of this coffee button you can copy.

  • Copy that.

  • HTML.

  • And you're gonna want to put it in your view and then the model.

  • We don't need it yet.

  • There's nothing dynamic yet, but go ahead and toss that in there because we're gonna be adding properties and methods and stuff on pretty soon s o.

  • Go ahead, take a couple of minutes on your own.

  • Thio, create the evil tender components that has this Each game I'll rendered as its view And then we'll go vers solution together and a few minutes.

  • Do you want to try toe and always feel free to raise your hands If you have any questions throughout the nights Happy.

  • I'm sorry.

  • Uh, yeah, we're going.

  • I'm trying naturally.

  • Try and see if you get it, You might just do we really see changes you?

  • Oh, she's you way.

  • Okay, Austin thinking I think the pressure's just hold it.

  • It's not going to live.

  • Sorry about that.

  • It feels like they're coming to a solution.

  • They've got.

  • Got it working.

  • I got 1234 five.

  • It's most people.

  • Okay, cool.

  • Let's let's go into a solution together.

  • Um, who wants to get me started?

  • You could give me stuff.

  • One.

  • Are there some one?

  • There's No, it's no actual step one.

  • All right.

  • Yeah.

  • Okay.

  • All right.

  • So what are the three things?

  • Uh, which is evil?

  • Tender.

  • Right.

  • Come with you.

  • You sweet.

  • Gonna totally copy.

  • Baseless.

  • From over here.

  • If you're ever frustrated with the alignments in in the editor, at least on a Mac, you can hold down the shift key and then click Thio another another like place in the documents.

  • And then you can tab everything all at once.

  • Uh okay.

  • So we've got our view, and then what's her last thing?

  • This, you know?

  • Yeah.

  • What's at that?

  • It's just gonna be an empty object.

  • Okay, We don't have anything rendered.

  • Jets.

  • What's your last step?

  • The market.

  • Yeah.

  • So in our issue, mobile puts a little tender.

  • All right, I'm gonna collapse this because we we don't need this enemy are All right, so we've got our We've got our custom element.

  • We've got our view.

  • It's actually rendering and pitch.

  • This looks good.

  • Those questions, comments.

  • Anything you guys want to talk about before we move on to the next up.

  • Cool.

  • All right, so, uh, Okay.

  • So if you keep scrolling down on the page, you'll see the solution section.

  • I'm gonna just out of habit.

  • I'm gonna copy paste this every time just to make sure I have exactly what's what's there.

  • So I'm all delete what's in the Java script and paste in.

  • And then it's probably exactly the same, uh, to make sure we're naming things the same.

  • Um Okay.

  • Uh, next.

  • Okay.

  • so we want to show.

  • So right now in, um, in our app, we have this, um, the scrimmage in this next image part coated.

  • We want to make this dynamic, so we wanna have an array of images.

  • So these are all of the Urals to the different characters that we have.

  • So instead of having these hard coded, we want to put this in our view model and then show a current image and a next image.

  • So our current image will just be whatever is first in the array and then the next images.

  • What's next?

  • On your way?

  • Um, so what do we need to know?

  • OK, so, um, we already actually talked about this a little bit.

  • So when we have properties in our view model, those air made available to us in our view.

  • So in this example, we add a profile.

  • It's property.

  • Basically all of the keys and this objects are the properties that we want to make available.

  • So we have this profile's property that's available to our view.

  • And then, um, this is Kendra specifics that were saying that the fault of the initial value for this property is going to be what's returned by this function.

  • So this little bit of syntax is the like.

  • Is the gutters and tax in Yes.

  • Five years.

  • Six.

  • Yes.

  • Yes.

  • Why?

  • I don't remember which, Uh, which suspect this was added in.

  • Um, so this is saying Okay, this this default is a function that returns returns in array.

  • So in this case, we're we just have an abbreviated version.

  • We just have the, uh, an array of a couple of things.

  • Um, And then, uh, the next thing about that is the so in this example, the profiles and the view comes from the view model.

  • And then there are helpers for being able to, like, do stuff in the template.

  • So we're not gonna go through all of the docks.

  • But there's helpers, like, if in each, and things be ableto do loops are conditional, sir.

  • That's for the thing.

  • Discussion.

  • Sorry.

  • You go.

  • Yeah.

  • So this so this view model has all of the properties and actions that are made are made available to our view and then sew for properties.

  • They basically have a like type definition.

  • So this is kind of like setting up what that property is gonna be like s.

  • So we have a This default getter is basically whatever the initial value is for the property, Um, there's a couple other will kind of get into a few other things that we can put in this type definition off like getters and centers and that sort of thing.

  • But to start off, we're just gonna have this default if it does that make more sense?

  • Yeah.

  • Does it?

  • Does it have anything to isn't course issue.

  • If it's getting images from different, there shouldn't be and way uploaded.

  • All of these images toe get abs, uh, server specifically because their servers ments for putting images, you know, wherever you want.

  • So that's why there shouldn't be any issues with loading these.

  • Good question.

  • Yeah.

  • Who's the national?

  • Yeah.

  • Okay, So basically, in our stash templates, wherever we have, um, Curly braces or double Curly's, that's where, like, stash is taking over, and it's gonna do something special.

  • So, like, here we have the double curlies, and then we're just printing a property, and that's kind of the most simple case.

  • And then second to that is whenever we have the hash, this means okay, I'm calling like a helper function.

  • That's that's made available by the template ing engine.

  • Um, so there's a bunch of different helpers, um, like, hash each hash if, uh, hash, just various things, and we'll we'll go through a few of these.

  • Does that make more sins?

  • Sweet.

  • Cool.

  • Any other questions before we?

  • Okay, so we've talked about, um, with the images that we want to show, We've talked about adding something to our view model to make it available to our view.

  • Um, and, uh, there's so one more kind of syntax that you can have in your view model is this getters and taxed.

  • So this isn't specific.

  • Thio Kanji s If you've seen the gutter syntax and again yes, five years.

  • Six.

  • I don't remember which speck.

  • Um, this is just saying, OK, eye, this is a property name, and then this is a like getter function for that.

  • So whatever is returned in this function is gonna be the value of that property.

  • So we could have done the same thing up here where this could have been, like, get profiles and then just returned the array.

  • Um, it's a saying a similar idea um, So this is gonna be helpful for us because you can imagine there's a current profile.

  • You might want to make a next profile.

  • And then this is how you can get something from the profiles array and in return it as the, um so you can create a life next profile property that gets the second thing.

  • School.

  • Any questions before let you loose?

  • No.

  • Okay, take a few minutes.

  • Uh, try and make the, um, let me go back to the beach.

  • We'll try and make this, uh, this current image and this next image dynamic with stuff that you put in are in the view model, so you don't wanna have the hard coded like image source here.

  • Um, you wanna have that be some value that you get from the view model.

  • Thank you.

  • And please, just put up your hands if you have any questions, I'm happy that explain more.

  • No.

  • Oh, Oh, yeah, That's it.

  • What?

  • Two.

  • Yeah, Who feels like they're starting to come thio a little bit of a solution.

  • Yeah.

  • All right.

  • We'll get through it together then.

  • Um who wants to get me started?

  • Where?

  • Where should I start?

  • from here.

  • The images changed the world sources.

  • Uh, sorry.

  • Say that again.

  • Classes, images, class current and getting source is that Did we do the same for this guy?

  • Uh, I'm gonna call this next profile image.

  • Okay.

  • I like where this is headed.

  • What's thanks?

  • Yeah, let's do it.

  • So, uh, should we start with profiles or the current profile and next profile?

  • Gethers?

  • Uh uh.

  • All right, let's do that.

  • So Well, do you get, uh, current profile?

  • Eso this is Ah, a kind of standard Syntex getter.

  • Eso in here.

  • We can return whatever we run, we want, uh, who's just got a line for me.

  • What should we were training?

  • Is that Yeah.

  • So we'll need to define this profile.

  • It's proper property.

  • But yet eso this, uh, profiles, like gets will do the same thing for next profile.

  • So we'll have a better for it, and then we'll return to stop profiles.

  • Life gets one since that's the second thing in the profiles, Ray, I went there last one.

  • It's the last little bit that we need, huh?

  • Yeah.

  • So, uh, we could say, like, it profiles and return this array.

  • So that's one way of doing it.

  • What we showed in the like what you need to know was a little bit of a difference in tax of saying, OK, we're gonna have a profile to property.

  • And then this object is what defines what that property is like.

  • So in here, this in tax kind of gives us a lot more options of what we can do.

  • So we could have the same thing as the getter syntax, uh, with a with get method that returns the array.

  • I think what we actually want to do is just define a default value, which is gonna be the array.

  • So the difference in like a default versus, uh get is that this is saying the this is an initial value.

  • It's not gonna change.

  • You can modify this property, but if you need an initial value or it's a fault value than here's one for you, where's the gets is saying any time you access this property, here's what you're here's what we're gonna try.

  • Um, Okay, so, uh, see, if this actually works so in the in the problem section, it says, um, we can kind of play around with the console to see if this, like, actually made it dynamic, right?

  • It looks the same.

  • I guess we could.

  • One way we could do it is we could remove stuff from here and see if it updates correctly.

  • Okay, so that's that's one way of testing it.

  • Another way is code pen makes consul available to us.

  • So in the bottom left, there's this console button.

  • You don't have to do this.

  • You don't have to follow along long, but I want to show it.

  • Um, So it has.

  • There's this council button that pops open this little section and then we can, uh, taste in what we had before.

  • So this is saying document taught pre selected.

  • This is like a native dom ap.

  • I, um native browser A p i that says I want to give you a CSS a lecture, and I want I want a single elements that matches that selector.

  • I want the first element that matches that selector.

  • So we're getting our evil tender, uh, custom elements on dhe.

  • Then on it is a view model property.

  • And then we've got all of the data that's in our few months.

  • So the same thing that's rendering.

  • The view is, in this view, model property.

  • So we're accessing profiles, and then we can call shift, which I have a hard time in spice.

  • The array methods shift is the one that pops off the first thing from the the first index seven or eight or zero index of Marie.

  • So when we run that inner council that'll actually, like, modify our view model, which updates to be on Do that again.

  • Do that a couple times.

  • We're gonna write code that does the same thing.

  • Cool.

  • Any questions before we move on?

  • Thio?

  • Uh, probably adding, like and new planets, any questions before we move on?

  • No.

  • Cool.

  • Okay, um, if you want to you India the same thing that I mean, d'oh every time under the solution, there's the copy button, and I'm gonna replace all of this.

  • I think it was I think it was basically the same thing and a different order, but same code.

  • Um okay, we're gonna have a like Clinton.

  • Okay, So when someone clicks on the like button, which is this this heart of the screen heart buddy, at the bottom.

  • We wanna counsel law liked, and then we want to remove the first profile image.

  • The same thing that we were doing in the consul earlier.

  • We would have removed the first profile image.

  • So it comes off the stack on dhe, then show the next one blissed.

  • Um, so what do we need to know?

  • Well, just like the example on the home page we can use on Colin syntax to listen to whatever event so we can listen for clicks events on that like button.

  • Um, and then inside here is the method in the view model that we want called.

  • So this isn't going to like coal That method as the temple is being rendered, it will call it once once the button has been clipped.

  • So in our view model, we can define a an action or a method like this.

  • And this is just kind of standards in tax for for defining a method so we can have do something, it can take arguments.

  • So, like in this example, we're passing dance from the view into the view model, and then when that button is collected, will make the alert on the last thing shift shift is what you're looking for.

  • Thio Pop off the zero index.

  • Uh, something interest.

  • Um, that's it.

  • Go and take a couple minutes.

  • Any questions before we break for her?

  • Oh, now, Okay, cool.

  • So you want to make this?

  • You wanna make this, like button, actually, like, who feels like they've come to a solution?

  • No.

  • Take another minute.

  • Go through a solution together.

  • What?

  • All right.

  • Who wants to get me started with a solution?

  • What should I do first?

  • Okay, let's see.

  • What do we want to call it?

  • Um, like, just like we'll go with lights profile.

  • Okay.

  • Uh, so we've got our our method inside here.

  • What do we want to d'oh, Huh?

  • Yeah.

  • Way to do both.

  • So well.

  • D'oh!

  • Consul Log, er, think all caps liked, and then they start profiles that shift, so we haven't quite gone over?

  • No.

  • Oh, that was exciting.

  • We're We're having screen that she's all right.

  • There we go.

  • That's okay.

  • Uh, let me switch back to not showing my face, Sweets.

  • Well, then, let's not have this be a 1,000,000 times smaller.

  • That's right, guys.

  • Uh, that's four sweet.

  • Okay.

  • All right.

  • I think we're back on track.

  • Get this right.

  • OK, Uh, OK, so, um, one thing we haven't like 100% talked about, but now it's as good A By the time it's ever so.

  • This this inside the inside of like the's skaters and this action.

  • This always refers to an instance of this view model.

  • So essentially, what Candace does is it takes this view model object, and it uses it as, uh, as like the base for creating new instances of the view model for each components.

  • So in our up, we only have the one instance of we only have this like one evil tender.

  • But if we had multiple evil tenders in here, they would each have their own instance of the view model.

  • So if we swiped on, I don't know if I can actually show those.

  • So if we like, um, we can show those not yet.

  • Okay, um, so if we like made modifications and one components, it would affect the other.

  • It's a new instance of the view model for every every, like HTML custom elements that's in the page.

  • Um, so that's what the this refers to.

  • Um, that's what the this refers to inside here.

  • Um, So Okay, so last thing we need to do is actually hook this up.

  • Um, so on our like button, I'm gonna add the on colon click, and we're not call, like, for a flyer.

  • So now when we click on, uh, then we click on the heart we've got the 1st 1 disappearing.

  • And then in our console, we can open up the the cocaine consul and we'll see lights, lights, lights For every time I've been clear that for every time that we click on the link Cool.

  • Any questions?

  • Moments?

  • No.

  • Okay, let's create a Nope.

  • But me I'll give you guys a minute or two and do basically the same thing.

  • Just hook up the note button, maybe at a common council log that says no ped.

  • Ah, actually, I'm gonna copy paste the solutions that we're all on the same page.

  • Yeah, this one had its method like so go ahead and create a, uh, working.

  • Nope.

  • But is there no button working?

  • Sweet.

  • Let's make this one work.

  • Okay?

  • So just will have our note method say notes.

  • Um, we're gonna do the same.

  • This profile of shift, we're not doing anything special.

  • There were just removing the top one.

  • And then on our dis buttons were going to say on click, you know, and call that method.

  • Then when we opened the consul, we should see when we click lights.

  • We've got lights on when we click.

  • Nope.

  • We've got notes.

  • Sweet.

  • Any questions?

  • All right, now we're gonna make this Maur Interactive, not just button clicks.

  • Now, when we swipe on, these images were actually gonna move them left and right.

  • So let's go through what we need to know for that.

  • Oh, actually, I'm gonna, like, always gonna call.

  • Keep the solution, make sure we're all on the same page.

  • Sweet.

  • Okay, um, So dragon moves the profile to the left and right.

  • So when as the user drags left her right, the image will essentially kind of just move left and right.

  • We're not gonna do, um, we're gonna keep it simple.

  • We're not going to do, like, complete tracking of, like, wherever your your house or your finger moves.

  • We're just gonna move, move horizontally.

  • Um, we wanted working on desktop and mobile, So if you were to pull out your phone, this would actually, like work on your on your IOS or enjoy advice.

  • Um, and the element that we want to move is the current one.

  • So we're gonna specifically like we specifically want this stiff to be the thing that we're moving back and forth.

  • We don't wanna move like anything else in our in the dawn.

  • So what do we need to know?

  • Okay, So the first thing is that the way that we're gonna move it is just with CSS.

  • So we're gonna assign a left style essentially to the image Thio Thio, move it back and forth.

  • So, essentially, this would be similar to if you Oh, that's not readable.

  • Oh, that's also not beautiful.

  • Um, move this.

  • No.

  • Okay, so this is the same as saying this this def.

  • That is that you can kind of see on the right that it's highlighting the grand image.

  • So this detective is what we want Thio manipulate to move back and forth.

  • So if we if we give it a left of 100 pixels, you can see that it'll it'll jump that way.

  • And then as we as we change this value, that's how we can have that image like being moving and then essentially, if we go into the negative values.

  • It's the same as, like, swiping left.

  • So positive negative values are allowed here.

  • So we want to do this except with Java script.

  • And we want to be able to have that actually track where the where the mouse is moving.

  • Um, so to do that, Um oh, sorry.

  • Last thing is that so we can sew in our in our view model, we can have, like, a left property or how far we have moved property and then render that in the in the view with the double Curly's.

  • So just like a normal HTML attributes, um, and then inside there will have the double Curly's for the view model property.

  • Um, so we'll do that will define how far we have moved as number again.

  • The view model.

  • It was just Whatever is to the right here is just saying, like, a type definition.

  • So this is a shorthand to say, number or string or any value or what have you?

  • Um, the next thing is that we're gonna need to listen for win the when the currents elements moves that current div when it moves.

  • So Candace has this way of listening for events.

  • Earth.

  • Let me take some cages has a way of being letting your code be notified when the custom element has come alive or spend inserted into the page.

  • So all of these view models are like new, unique and senses.

  • And when a new one is created for an element that's in the page, this connected callback method is called on your view model on and it's given and you're given the custom elements.

  • So in our case, this l would be this l variable would be the evil, tender custom elements.

  • Um, this matches the custom elements spec.

  • So this isn't basically candy ass matches.

  • What is what is specified in the custom elements spec So connected callback lets us know.

  • Okay, our element has been inserted into the dawn, which means we can start, like, doing dog related things so we can get a reference to our two that div to this.

  • Where is it to this current div?

  • By using the query selector method that's on every each male dumb What?

  • Um, so that's how we can get a reference to currents and then candy is gives us a way to listen to events.

  • And before I get into the candy s part, I want to talk about, um I want to talk about that.

  • So for years, they were just desktop browsers that had events like mouse over, mouse out mouths move, mouse, mouse, old defense.

  • Right.

  • And then I started having mobile browsers, and there was a different if you and I was implemented that we're all touching them.

  • So instead that mouse mouse events, it was all touch of its on.

  • Eventually, most of the browsers came to a consensus to implements what's called the Pointer events.

  • FBI.

  • So this is, uh, this is a standard AP.

  • I essentially mels together the mouse and touch events and puts it into pointer events.

  • So, like mouse down, there is a point or down or mouse moves.

  • There is a point, Of course, not all devices are going to fire all of the same events, right?

  • Like there's, um, for stuff that would be related to hover.

  • You don't have, like a hover state in on mobile, right?

  • But, um, for um, for things where there are, there is analogy.

  • There's pointer events.

  • Every browser except one has implemented the suspect that one browser is so far, it's not in their necks for its safari.

  • Actually, I don't know if Internet Explorer ever supported it.

  • I know.

  • EJ supports pointer events.

  • Safari on Let's stop in Mobile They So far they have refused to implement um, so we can use what's called Polly Phil, who's who started the term police before?

  • Okay, a few people.

  • So Polly Phil basically says, Okay, I'm gonna write JavaScript Thio mimic the same AP eyes that are native Thio browser.

  • If they were to implement those AP eyes So, um, in our code time, I actually already set this up.

  • So under settings, you'll under javascript.

  • I added this pep Js um pointer event.

  • Uh, I can't remember what the P stands for.

  • It's a Polly Phil for for safari.

  • So that's already loaded.

  • If you pulled it out on your on your phone on an IOS devices just work.

  • So we're gonna be able to use these pointer events and just not give any cares about so far a support so we can listen to these events with some AP eyes that candy ass provides.

  • So this don't listen to you is an A p I inside of our view model that lets us provide three things.

  • The object that we want to listen to, the events that we wantto listen that are being dispatched from that object and then a callback win those events fire.

  • So in our case, we want to listen for, um, we want to listen on the current div whenever there's a clincher down, which is like a mouse down or a touchdown.

  • Um, I don't know if the event is actually called Touchdown, but, uh, we want to listen to a pointer down events, and then when that happens, we'll have our code.

  • We'll have a callback Halt.

  • Um, we already talked about the O the P stands for political pointer events.

  • Police.

  • That's Pepsi s.

  • Um, there's a couple of the attributes that we need.

  • S O.

  • You know, this earlier when I was when I was dragging with our code, as is like, the browser will be helpful and be like, Oh, you're you're You're, like, dragging in the image.

  • Let me give you that to you so you can put it somewhere else or whatever we want.

  • Oh, we do not want the browser to do that.

  • So there's a couple of attributes that we can that we can add.

  • So there's a touch action on mobile devices on drag a ble drag a ble False.

  • It's what we can use for just stop browsers.

  • So say, Don't give me the default driving behavior but us handle it on our, um and then the so inside way already talked about, like listening to pointer down events.

  • So inside of our callback, we have access to this events.

  • Variable, that's past your callback events has the super useful property of clients X, which is the current position of the pointer device.

  • Mouse finger.

  • What have you.

  • So this is what we can use to see where the mass is current.

  • So that's gonna be super helpful, because when there's a pointer down events, we can grab the event dot client X and have that be our starting place.

  • And then when we receive any other player events for the for the movement of the mess, that's how we can calculate the delta between our starting place and then wherever the user currently as which is how we can do the left positioning essentially so this will be so in.

  • Pointer down.

  • We can listen for that.

  • Find out the initial value on and then we can listen to point or move to man.

  • The mouse is actually moving or your finger is actually moving across the street.

  • Uh, this is a little bit different.

  • So pointer move.

  • So here were listening on documents.

  • Anyone want to guess why we would listen on document instead?

  • As current I want to stop moving.

  • It will be for a while, and then eventually you're gonna be moving off of it, and or you would otherwise be moving off of where it is initially, positions.

  • And then you lose track of those events s.

  • Oh, that's why we want to listen anywhere in our in the document body.

  • We want to listen for a point mute on, and that gives us access to that same plant on the events.

  • Um okay, So what would happen if you grip if you if the mouse started somewhere outside the pictures framed?

  • Yeah, which I think for us.

  • It matters that if you start dragging and then if you drag off of where the the image would be positions, then you're not gonna get those events fired.

  • So that's why it matters.

  • Anarchist.

  • That was a lot that we just went over.

  • So I want to take a quick recap.

  • So what we What we want to do right now is we wantto add that style that left style, um, so that we can move the move, the current image left or right, And then we wantto set up this the property interview model.

  • We want to set up our connected call back so that we can add these, uh, this start listen to callbacks.

  • And we want to listen to point her down as our start complain your moves for a CZ, the user is moving, and there's a couple of h male attributes that you'll need to add to the image to make sure that you don't get the default dragon behavior.

  • Um, it's gonna be really awkward, because at this point there's no, like, cleaner up or whatever the event is for, like letting go.

  • So when you have this working, it's just gonna keep on like after pointer down.

  • It's just gonna keep on following your mouse.

  • That's okay.

  • We're gonna will will do that in the next step any questions for you?

  • Act on your own.

  • Cool.

  • Well, take longer for this.

  • Well, we'll take like he's five or 10 minutes.

  • Please feel free to raise your hands if you have questions.

  • Clothes?

  • Uh huh.

  • Oh, well.

  • Oh, what?

  • What?

  • Hey!

  • Oh, he's Yeah.

  • Last four council are just like, yeah, that with ours comes from or what?

  • The first users.

  • Oh, you How do you come to that person?

  • One Didn't the profile.

  • It's way bars here on as the hole profiles Ray this'll British same service.

  • So glorious.

  • Deepened today said that through Let's go.

  • Yeah.

  • So Thio connect the two people in terms of like what actually happens is when you're slacking.

  • Um, I'm sure, So they I'm guessing that they're living the so they've got their like that wins a guy service for actually getting old profiles.

  • It wouldn't surprise me.

  • A lot of the basic mechanics of fetching a list of like 10 years.

  • Honey like profiles is similar.

  • Said how, like we have our race off lusts.

  • And then, as people are swiping, we're doing the same thing like you removed from their list of, like, local profiles that my success and then, um, you know, when the person likes First Slice left her nights and they're sending that, they're making FBI call.

  • So we put a consul they would be making on FBI.

  • Holt say, OK, this person lighter didn't like and it's been a while since I'd be sooner.

  • But if I remember correctly, been old immediately.

  • Sell used if it's a ship.

  • So they do that a couple different ways where maybe after the slime is When did you get me?

  • I call, you know, if it was a natural, Maybe they already know.

  • Maybe they already have it.

  • Implant that if they swipe right, it will be in cash.

  • If there's like No, just.

  • And then there were so many would probably a different FBI messaging part.

  • Okay, well, the wicked witch And then both sweat rates and then rip them soon.

  • Yeah, whatever that would be.

  • Yeah.

  • Yeah.

  • Bill says questions like, Yeah, I know.

  • Certainly connected.

  • Tolerate that.

  • That's reserved for you.

  • So what is that?

  • It is these, uh, so second call that, like, having built in here just had one another Damn liver, because most any logic that it lost because, like you just Oh, yeah, you could.

  • You could actually start, so But we're just going through everything Thio connected.

  • Call that.

  • But remember.

  • So this this is this is the instance of the model so you could have other methods Designs into you.

  • Yeah, Yeah, yeah.

  • All right.

  • We'll start going through a solution together.

  • Um, who wants to give me start?

  • What should we eat?

  • You first.

  • No, you James.

  • Yeah.

  • Let's do it.

  • What am I changing?

  • And, uh, yeah, so, uh, what was this called?

  • How far removed?

  • Maybe that's all run with this.

  • All right.

  • Eh, So we okay, so we add the style property to the current This the class current If eso we'll have this how far we moved property in our view model.

  • Let's go ahead.

  • And at that.

  • So at the bottom, I'm just gonna check things onto the bottom.

  • Said the bottom.

  • We're gonna have a tougher we moved, and it's a number.

  • Uh, we won't do anything with that.

  • Okay, what's next?

  • What should we do next?

  • Yeah, let's do that.

  • Because otherwise we're not gonna actually be able to drag so touch action.

  • It's took touch, action none, and then drinkable close.

  • Okay, Sweet.

  • Uh, what's next?

  • That turns off the default problems.

  • Yeah.

  • So now So, like with Dragonball false.

  • Now when we drag, we don't get the default browser.

  • Um, behavior.

  • If we remove the trackable, that's that's where, like, you know, show the dragged image for us.

  • We're connected.

  • Yeah.

  • Let's do it.

  • Okay, so we're gonna say connect Thio connected callbacks.

  • We're given the element, which is the the evil tender custom elements.

  • Um, so in here, we're gonna want to listen for the pointer down and the pointer move.

  • Bets.

  • Um, so let's say it's not Listen to you.

  • Um oh, First we're gonna need the current elements.

  • So let's say current is Eldad queried selector.

  • Basically, this is saying like we could do document the period selector, and then this would give us all of the dot or the first stop current in the entire document.

  • But we want it specifically for our elements for our request.

  • Melon mint.

  • So if there were multiple instances of it in the page, then we'd get the right one.

  • Um, so we're going to be a currents, and then we're gonna listen to we wanna listen on currents uh, for the pointer down.

  • And then we have our callback.

  • So when this is called, that's when the user actually presses down.

  • Okay, What should we do?

  • This defined very well to fact Nick's.

  • Yeah.

  • Okay.

  • So we could do, uh, like, um, uh, how do we wanna do?

  • This was started.

  • Okay, so we'll have star necks and then we'll assign start X two, Clan X.

  • That Kleenex.

  • Okay, cool.

  • Okay, so now we have when user presses down.

  • Uh, What's next?

  • Yeah, let's do that.

  • So I'm gonna basis no grounds.

  • So now we have you want to listen to pointer moves, and then this is where we can set the how far removed property.

  • So how far rem

Hello and welcome to a live stream of done.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

Tinderのようなスワイプカルーセルを作ろう (Let’s Build a Tinder-Like Swipe Carousel)

  • 2 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語