Can JS Proxies do "method missing"?

  Рет қаралды 3,300

Andrew Burgess

Andrew Burgess

Күн бұрын

Пікірлер: 25
@andrew-burgess
@andrew-burgess 5 ай бұрын
I use TypeScript in this example just because it's easier to be explicit about return types, expectations, etc ... and because I enjoy TS! However, proxies are widely available in JS, and you don't need to be using TypeScript to give this a try. I guess you won't get the editor hints for the `find` functions, but everything else will work.
@rak3shpai
@rak3shpai 5 ай бұрын
This is how tRPC works. You define functions on the server, and tRPC uses proxies to make it seem like it's available on the client, with type-safety and all, and internally handles serialising the call over HTTP. It's pretty neat.
@JarheadCrayonEater
@JarheadCrayonEater 5 ай бұрын
Nice! Years ago I worked for an employer that was creating metrology lab automation software, and I was responsible for the project since I'm a former calibration tech, metrologist, and dev for 35+ years. The project was using node-red to allow end-users to create automated calibration procedures that would either ask the user for input during the calibration or directly acquire the data from hardware, perform some checks on or calculations on the data, make a pass/fail decision, and store the result(s). However, node-red was not 100% up to the task, since there are fundamental parts of the internals that they don't expose. So, I started by forking node-red and customizing it to our liking, but that turned into a maintenance nightmare, and we quickly realized that altering node-reds behavior at runtime was the best approach. So, I started using Proxies to trap internal node-red calls, altering either the data going in, out, or sometimes both, depending on the needs. Anyway, thanks for bringing up this somewhat lost part of JS!
@TheProcessor
@TheProcessor 5 ай бұрын
immer is a fantastic example of Proxy usage
@ryandsouza2962
@ryandsouza2962 4 ай бұрын
Great vid! I love proxies and I use them in Vanilla JS/TS for two-way data binding
@Douwab
@Douwab 5 ай бұрын
Like always, very interesting video and really nice and fun usage of Proxies imo! :)
@paoloricciuti
@paoloricciuti 5 ай бұрын
Trpc is using proxies... specifically recursice proxies to keep track of all the nested property access you do and convert that to an id that is passed to the trpc router to call the proper method on it. Pretty interesting
@0xtz_
@0xtz_ 5 ай бұрын
wow 😯, that's coool man we need more videos like this with Ts ofc 😂
@forinda
@forinda 5 ай бұрын
Vuejs objects are almost all proxies
@danielsharp2402
@danielsharp2402 5 ай бұрын
For anything that isn't a getter/setter (maybe getter and setter as well, not sure how that interacts with Object.keys) you can just map over the keys and create the object yourself or am I missing something?
@Michaeljamieson10
@Michaeljamieson10 5 ай бұрын
legend state for react and react native uses proxies
@AppleGameification
@AppleGameification 5 ай бұрын
Huh, I've never looked into proxies before but I think I recognise this as what Vue uses to implement reactivity when you change a value in an object?
@wobsoriano
@wobsoriano 5 ай бұрын
Yeah, Vue 3 uses it.
@azizsafudin
@azizsafudin 5 ай бұрын
Valtio uses proxies extensively to manage state!
@parlor3115
@parlor3115 5 ай бұрын
Unless you're developing a library with very tight user experience constraints, I don't think proxies should be touched. It's the worse thing for readability, I've ever interacted with in JS
@phamiersc2179
@phamiersc2179 5 ай бұрын
VueJS uses proxies!
@phamiersc2179
@phamiersc2179 5 ай бұрын
Everything state related in Vue is a proxy, that's why you do not need to use callbacks for mutation in Vue, you just mutate state directly, render micro task is created automatically
@edgeeffect
@edgeeffect 5 ай бұрын
I've come across Active Record and Method Missing multiple times in Ruby and Laravel and I've got to say, they're the work of the devil himself.
@Guergeiro
@Guergeiro 5 ай бұрын
Proxies are actually a design pattern. It always felt weird to me that the language has a construct that represents a pattern, and feels badly implemented for consuming it honestly. Why JS had to do this? Don't know, but I think implementing the pattern yourself is way cleaner and easy to follow than using the native construct.
@andrew-burgess
@andrew-burgess 5 ай бұрын
Hmm, interesting take! Do you have an example of implementing this manually instead of using the native Proxy? Thanks for watching & commenting!
@Guergeiro
@Guergeiro 5 ай бұрын
@@andrew-burgess I posted a comment that had a TS playground that for some reason got deleted...
@angelhdzdev
@angelhdzdev 4 ай бұрын
@@Guergeiro KZbin marks comments with URLs as spam... :(
@andrew-burgess
@andrew-burgess 4 ай бұрын
@@Guergeiro ah, sorry, I can't control that youtube behaviour. If you still have the link, wanna email it to me? you can find my email on my website, linked in the video description.
@meyou118
@meyou118 5 ай бұрын
nice. very clever. another example why AI can ever replace human ingenuity.
What are JavaScript Generators and Iterators?
10:28
Andrew Burgess
Рет қаралды 7 М.
How to use WeakMap and WeakSet in JavaScript
7:02
Andrew Burgess
Рет қаралды 5 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Actual use case for JavaScript PROXY!
13:09
Kevin Ghadyani - JavaScript
Рет қаралды 14 М.
old TypeScript syntax I just discovered
8:54
Andrew Burgess
Рет қаралды 4,2 М.
Is This the End of Crossplane? Compose Kubernetes Resources with kro
30:01
will i never understand this? unknown.
12:05
Andrew Burgess
Рет қаралды 4 М.
Welcome to Async Generators in JavaScript
10:53
Andrew Burgess
Рет қаралды 6 М.
I tried React and it Ruined My Life
1:19:10
Tsoding Daily
Рет қаралды 158 М.
A Practical Guide to JavaScript Proxy Objects
14:19
TomDoesTech
Рет қаралды 7 М.
how TypeScript 5.5 makes safer types in fewer keystrokes
7:48
Andrew Burgess
Рет қаралды 4,4 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН