So I think that's an improvement and we could go as far as, you know, directly pasting this in line, cause it's going to return it's off function. But I feel like that's a little too much. I feel like that's just one step beyond what we need to do. All right. And for our big final refactor move, again, this is all just kind of a nicer way of writing what we had written before let's structurally change it right now, this code is very imperative. Um, meaning it's just step-by-step it's like walk the DOM tree for every iteration, check for an attribute, get that attribute, register a listener. You know, we're maintain ability-wise that's not always the most maintainable. So if you think about what's the code that I want to maintain, if this is my little framework, what's the code that if I needed to add a new attribute, like flame text, I would have to copy all this, maybe this would get huge. And it's all inside this walker. It's like, what if I just went to fantasy land and wrote what I want? Well, let's, instead of calling it attributes, let's call it directive. So what if I said directive? And then I could just say something like flame click, and then let's just take this whole callback right here. Okay. And, and these even, like these are all individual parameters being passed. I would rather turn this into an object of things being passed in so that I could just pick and choose which things I want to like, oh, I only want the element. Or I only want the on remove, or I only want the expression. So yeah, this is designed by wishful thinking. To me, this is like. A much better way to do it. So register the directive, sort of declare the directives. This is a more declarative approach to clear the directives up front, and now inside of this walker have some method like boot or something like boot element. And then this directive function registers a directive in a pile of directives, and then boot goes through all those directives and actually boots them. So let's write that we're going to break out of our utils right now. And we're going to create a new file called directives dot JS. This is another thing I like to do. Is it's called, I call it the single file principle is when you're writing functions that belong together, you put them in a single file. So like anything having to do with directives goes in a single file. That way you always know where to find it. Um, if you're used to object oriented programming, like PHP or Python or Python or Java or something, you're used to writing classes like this. Well, I don't really use classes in JavaScript. I more use these modules, these files, where instead of methods, I have functions.
Comments