Four examples of strange ways to bind HTML to nested objects that contain writable stores!

This page summarizes the projects mentioned and recommended in the original post on /r/sveltejs

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • Node RED

    Low-code programming for event-driven applications

  • Now, from a broader perspective, creating application that allow users to safely create code like https://nodered.org/, or https://www.svelvet.io/.

  • proxy-www

    学会 Proxy 就可以为所欲为吗?对,学会 Proxy 就可以为所欲为!

  • I have eliminated the need for stores in my tree by using proxies, my original little component inventions are very efficient a value changes in a store, I assign it to innerHtml. A store is just a nerfed emitter, it is a tiny little useful program. I don't know what svelte does, when it detects a change to a large nested tree. Does it re-render the whole thing, does it do dom or object, or both diffing, I am not sure. It should observe changes on a property level, like spreadsheet programs. But, browsers, diffing, shadow DOMs and computers are fast today, so as I was going over the twisty litte passages, I also rewrote my tree. In a really crazy way, and you really need to know about this, because when you use Object proxies, then svelte becomes ideal for nested objects. Let me show you how proxies work: https://github.com/justjavac/proxy-www This brilliant person made a www object, that is a proxy, meaning he can intercept the next property. in this case www.baidu, and return a proxy again to capture the data, which in this case is .com when .then is called. It then makes a request to www.baidu.com www.baidu.com.then(response => { console.log(response.status); // ==> 200 }) THIS TYPE OF REFERENCING MAKES SVELTE DEEPLY HAPPY, when the www is a variable that you are referencing in the DOM. Let's go to my tree now. tree is an instance of a normal Tree class, it has children, element, thype of stuff. But I also gave it a proxy... the read property is a proxy that will return a node this way: tree.read.abc.context.filename tree.read is a getter, that returns a proxy. that will spy on the next thing after the dot, in this case abc, which is a node id. it will grab that node and return it, for binding via bind: here I bind to context.filename, but I could bind to tree.read.abc.name which is a lable for the node. filename: {tree.read.abc.context.filename} input.name: THIS ACTUALLY WORKS tree.read.abc.name = 'Hello World', will re-render the UI. Because SVELTE does not care that read is a proxy, it only sees assignment to tree.something.something.something.something It does not care that .read.abc is not real data, though it returns the node object, it is not where the object really is. --- I think we have reached the limit of being able to communicate ideas, my concluding thought is: No, svelte does not not turn a nested object into nested writables, but it is OK, because simplicity has its benefits too. We can lie that tree.read.abc or even ($tree.read.abc if via import) is where out data is at, and say thing like tree.read.abc.name = 'Hello World', to really kick bubble gum. The store ends at your object bounday though it does not go inside, all the properties within are just nested POJO properties, BUT, svelte will detect changes anyway, so as long as you clearly refer to the ROOT object. In my case tree. in your case $data. One last thing to underline, between us noobs, you use stores when you can't bind:data for some reason. The store pipeline, is to be used, when you can't bind easily. Learn to use the proxies, they are of JavaScript not svelte, but they let you bind very deeply into complex data structures, and make an assignment, which svelte will then notice, and re-render the UI. Good luck, here is your program without stores, you don't need to use them if you don't need them: https://svelte.dev/repl/21f8cc38cf3e4b64b824d7c7b702d17b?version=3.44.3

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts