daniel, to vuejs
@daniel@roe.dev avatar

Another stream - I fell into a trap 🚨 and will be building/discussing a #vuejs integration for https://www.convex.dev with @ballingt today ...

▶️ Streaming now on https://twitch.tv/danielroe

athlon, to random
@athlon@mastodon.social avatar

Fun fact of the day:

In Vue.JS, if (for testing purposes) you want to hide an element WITHOUT commenting it out, the v-show="false" won't work.

But v-show="!true" works fine.

vintprox,
@vintprox@techhub.social avatar

@athlon Well, that's annoying! It's a frigging v- attribute that must support JS expressions out-of-the-box, but can't handle a simple boolean expected in v-show? :0530: What have you become, ...

inautilo, to react
@inautilo@mastodon.social avatar


HTML attributes vs. DOM properties · What fewer and fewer developers seem to know https://ilo.im/15ynz8


joe, to javascript

In last week’s post, I said, “That is because you can not pass an array directly into a web component”. I said that I might take a moment at some point to talk about how you could do that. Well, today is the day we are doing that.

Let’s start with a basic Lit example.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

You will notice that the ArrayList class has an items property that is an array type. Lit won’t let you do something like <array-list items = ['Item 1', 'Item 2', 'Item 3']></array-list> but it is fine with you passing it in using javascript. That means that myList.items = ['Item 1', 'Item 2', 'Item 3']; does the job, fine.

So, how can we do that with a Vue.js array?

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

It is the same thing except you need to set the value of the list in an onMounted() lifecycle hook.

What about if we want to do it with React?

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

With React, you just set the value in a useEffect() React hook.

https://jws.news/2024/how-to-pass-an-array-as-a-property-into-a-web-component/

ewen, to python French
@ewen@mastodon.fedi.bzh avatar
kfdm, to django
@kfdm@social.tsun.co avatar

Working with and I'm using custom tokens so that VueJS and Django tokens don't conflict, but I also have a need to escape to ensure users can't get my VueJS delimiters anywhere.
Is there a place I can hook in to add my own, additional escape code 🤔, or am I doomed to have to add {{value|myescape}} everywhere a value is used 😢

joe, (edited ) to javascript

Earlier this week, when I wrote about how to build an autocomplete using Vue.js, it was less about exploring how to do it and more about documenting recent work that used Vuetify. I wanted to use today’s post to go in the other direction. Recently, I discovered the value of using Lit when writing Web Components. I wanted to see if we could go from the HTML / CSS example to a proper web component.

First crack at it

Lit is powerful. You can do a lot with it. Let’s start with a rewrite of Tuesday’s final example to one that uses just Lit.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

The first thing that we do in this is to import LitElement, html, css from a CDN. Our CountySelector class extends LitElement and then customElements.define('county-selector', CountySelector) at the bottom of the page is what turns our class into a tag. The static styles definition is how you style the tag. You will notice that there aren’t any styles outside of that. The markup is all defined in render() near the bottom. The async fetchCounties() method gets the list of counties from the data.jws.app site that I created last week.

This works but web components are supposed to be reusable and this isn’t reusable enough, though.

How do we increase reusability?

As you might remember from last month’s post about web components, you can use properties with a web component. This means that the placeholder and the options for the autocomplete can be passed in as properties in the markup.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

You will notice that the big difference between this version and the first one is that we dropped the API call and replaced it with a countyList property that defines the options. We can do better, though.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

In this next version, we eliminate all explicit references to counties since a person might presumably want to use the component for something other than counties. You might want to use it to prompt a user for ice cream flavors or pizza toppings.

How do you use Vue with a web component?

Unfortunately, you aren’t going to be able to use something like v-model with a web component. There are other ways to bind to form inputs, though. Let’s take a look.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

In the above example, optionsList and selectedOption are defined as Refs. The ref object is mutable (you can assign new values to .value) and it is reactive (any read operations to .value are tracked, and write operations will trigger associated effects). The options list can be passed into the web component using the :optionsList property. You might notice, though that the example is using .join(', ') to convert the array to a comma-delimited list. That is because you can not pass an array directly into a web component. That is likely going to be the subject of a future article. You might also notice that it is triggering the when you click on a suggestion and onBlur. The dispatchEvent() method sends an event to the object, invoking the affected event listeners in the appropriate order. That should trigger updateSelectedOption when you select a county or finish typing one that isn’t in the list.

So, what do you think? Do you have any questions? Feel free to drop a comment, below.

https://jws.news/2024/how-to-implement-an-autocomplete-using-web-components/

joe, (edited ) to webdev

Have you ever stumbled upon those form fields that suggest options in a drop-down as you type, like when you’re entering a street address? It turns out, that making those are not as difficult as you would think! Today, I’m gonna walk you through three cool ways to pull it off using Vue.js. Let’s dive in!

Vuetify

If you are a Vue developer, you have likely used Vuetify at some point. It is an open-source UI library that offers Vue Components for all sorts of things. One of those things just happens to be Autocompletes.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

Last week, I spoke about creating a repository of data for coding examples. The first one is a list of counties in the state of Wisconsin. In this example, the values from the API are stored in a counties array, the value that you entered into the input is stored in a selectedCounty variable, and the fetchCounties method fetches the values from the API. Thanks to the v-autocomplete component, it is super easy using Vuetify.

Shoelace

Shoelace (now known as Web Awesome) doesn’t have a built-in autocomplete element but there is a stretch goal on their kickstarter to add one. That means that we need to build the functionality ourselves.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

Our Shoelace version has a filteredCounties variable so that we can control what is shown in the suggestions and a selectCounty method to let the user click on one of the suggestions.

Plain HTML and CSS

We have already established that Shoelace doesn’t have an autocomplete but neither does Bulma or Bootstrap. So, I figured that we would try a pure HTML and CSS autocomplete.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

This is very similar to our Shoelace example but with some extra CSS on the input. You might be wondering about that autocomplete attribute on the input. It is a different type of autocomplete. The autocomplete attribute specifies if browsers should try to predict the value of an input field or not. You still need to roll your own for the suggestions.

https://jws.news/2024/how-to-impliment-an-autocomplete-using-vue/

array, to random
@array@fosstodon.org avatar

The story of my life when developing some web project is mostly always the same: I can surf on the code waves for a while... And then some apparently minor, silly detail got me stuck for hours. Now it's been a Vue component that refuses to display a selected placeholder by default, so you don't have to stare at an empty select bar. Yes, I've tried that already but no dice. Will I make it? Yeah, or bust. :D

lil5,
@lil5@fosstodon.org avatar

@danielsiepmann @array The most important thing to remind oneself is that in the end it’s just rendered in the browser, , , , are just reactive template engines (with state machines).

The question here is: is this an HTML or state-machine fix?

inautilo, to javascript
@inautilo@mastodon.social avatar


Comparing JavaScript frameworks (Part 1) · Let’s compare the template languages of the frameworks https://ilo.im/15yeds


joe, to javascript

I have been spending a lot of the past month working on a Vue / Firebase side project, so this is going to be a fairly short post. I recently discovered that there are modifiers for v-model in Vue. I wanted to take a moment to cover what they do.

.lazy

Instead of the change being reflected the moment you make it, this modifier makes it so that the change syncs after change events.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

.number

This modifier uses parseFloat() to cast the value as a number. This is a good one to use with inputs that you are already using type=”number” with.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

.trim

This one is pretty straight-forward. It simply trims any extra whitespace off of the string.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

https://jws.news/2024/v-model-modifiers-in-vue/

davidbisset, to markdown
@davidbisset@phpc.social avatar

VitePress is a Static Site Generator (SSG) that takes , applies a theme to it, and generates static HTML pages. Built on .

https://blog.vuejs.org/posts/vitepress-1.0

leanpub, to vuejs
@leanpub@mastodon.social avatar

Practical Vue 3: Discover the power of the new Vue 3 https://leanpub.com/book-vue-3 by Daniel Schmitz is the featured book on the Leanpub homepage! https://leanpub.com

joe, (edited ) to javascript

Earlier this week, we started looking at React and I figured that for today’s post, we should take a look at the https://react.dev/reference/react/useEffect and https://react.dev/reference/react/useMemo React Hooks. Hooks are functions that let you “hook into” React state and lifecycle features from function components. In yesterday’s post, we used https://codepen.io/steinbring/pen/GRLoGob/959ce699f499a7756cf6528eb3923f75. That is another React Hook. The useState Hook allows us to track state in a function component (not unlike how we used Pinia or Vuex with Vue.js).

The useEffect React hook lets you perform side effects in functional components, such as fetching data, subscribing to a service, or manually changing the DOM. It can be configured to run after every render or only when certain values change, by specifying dependencies in its second argument array. The useMemo React hook memoizes expensive calculations in your component, preventing them from being recomputed on every render unless specified dependencies change. This optimization technique can significantly improve performance in resource-intensive applications by caching computed values.

Let’s take a look at a quick useEffect, first. For the first demo, we will use useEffect and useState to tell the user what the current time is.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

Let’s walk through what we have going on here. The App() function is returning JSX containing <p>The current time is {currentTime}</p> and currentTime is defined by setCurrentTime. The code block useEffect(() => {}); executes whenever the state changes and can be used to do something like fetching data or talking to an authentication service. It also fires when the page first renders. So, what does that empty dependency array (,[]) do in useEffect(() => {},[]);? It makes sure that useEffect only runs one time instead of running whenever the state changes.

We can get a little crazier from here by incorporating the setInterval() method.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

In this example, it still runs useEffect(() => {},[]); only once (instead of whenever the state changes) but it uses setInterval() inside of useEffect to refresh the state once every 1000 milliseconds.

Let’s take a look at another example.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

In this one, we have three form elements: a number picker for “digits of pi”, a color picker for changing the background, and a read-only textarea field that shows the value of π to the precision specified in the “digits of pi” input. With no dependency array on useEffect(() => {});, whenever either “Digits of Pi” or the color picker change, useEffect is triggered. If you open the console and make a change, you can see how it is triggered once when you change the background color and twice when you change the digits of pi. Why? It does that because when you change the number of digits, it also changes the value of pi and you get one execution per state change.

So, how can we cut down on the number of executions? That is where useMemo() comes in. Let’s take a look at how it works.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

In this revision, instead of piValue having a state, it is “memoized” and the value of the variable only changes if the value of digits changes. In this version, we are also adding a dependency array to useEffect() so that it only executes if the value of color changes. Alternatively, you could also just have two . Let’s take a look at that.

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

If you throw open your console and change the two input values, you will see that it is no longer triggering useEffect() twice when changing the number of digits.

Have any questions, comments, etc? Feel free to drop a comment, below.

https://jws.news/2024/exploring-useeffect-and-usememo-in-react/

joe, (edited ) to javascript

Over the years, we have looked at jQuery, AngularJS, Rivets, and Vue.js. I figured that it was time to add React to the list. Facebook developed React for building user interfaces. The big difference between Vue and React is that React uses one-way binding whereas Vue uses two-way binding. With React, data flows downward from parent components to child components and to communicate data back up to the parent component, you would need to use a state management library like Redux. React is also a library where Vue.js is a framework, so React is closer to Rivets. You can run React with or without JSX and write it with or without a framework like Next.js.

Let’s look at how binding works in React and how it compares to Vue. In Vue, if we wanted to bind a form input to a text value, it would look like this

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

… and to do the same thing in React, it would look like this

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

You will notice that the React version uses the useState React Hook. Where the Vue version uses const inputText = ref('Blah Blah Blah'); for reactive state management, React uses const [inputText, setInputText] = React.useState('Blah Blah Blah'); to manage state. Also, Vue has two-way binding with the v-model directive but with React, the text updates when the state changes, but the state doesn’t automatically update when the input is edited. To deal with this, you manually handle updates to the input’s value via an onChange event. The developer is responsible for triggering state changes using the state updater functions in React. Another big difference is that Vue uses a template syntax that is closer to HTML while with React, JSX is used to define the component’s markup directly within JavaScript.

Let’s take a look at one more example

See the Pen by Joe Steinbring (@steinbring)
on CodePen.

This example is very similar to what we had before but now there are child elements for setInputText(event.target.value)} /> and <TextDisplay text={inputText} />. This approach promotes code reusability. By encapsulating the input field and display logic into separate components, these pieces can easily be reused throughout the application or even in different projects, reducing duplication and fostering consistency. It is kind of the React way. Each component is responsible for its own functionality — InputForm manages the user input while TextDisplay is solely concerned with presenting text. This separation of concerns makes the codebase easier to navigate, understand, and debug as the application grows in complexity.

Have a question, comment, etc? Feel free to drop a comment.

https://jws.news/2024/it-is-time-to-play-with-react/

#JavaScript #JSX #React #VueJs

mountaincampch, to drupal
@mountaincampch@drupal.community avatar

🏒 Big shoutout to HOCKEY CLUB DAVOS AG for their generous sponsorship of the prizes for the quiz at #DrupalMountainCamp!

🏔️ Mark your calendars for the upcoming hockey games: https://www.hcd.ch/de/team/spielplan

🎉 Congratulations to our quiz winners!

🍻 Thank you Monsteiner for sponsoring the beer for the Apreo event.

❤️ A heartfelt thanks to everyone who participated today!

#drupal #drupalCH #reactjs #vuejs #hcd

joe, to vuejs

This past autumn, I started playing around with the Composition API, and at the October 2023 Hack and Tell, I put that knowledge into writing a “Job Tracker“. The job tracker used Vuex and Firebase Authentication to log a user in using their Google credentials. With const store = useStore() on your view, you can do something like Welcome, {{user.data.displayName}} but using this technique you can also use …

const LoginWithGoogle = async () => {<br></br>try {<br></br>await store.dispatch('loginWithGoogle')<br></br>router.push('/')<br></br>}<br></br>catch (err) {<br></br>error.value = err.message<br></br>}<br></br>}

… to kick off the authentication of the user. I want to use it to finally finish the State Parks app but I also want to use Pinia instead of Vuex, I wanted the resulting app to be a PWA, and I wanted to allow the user to log in with more than just Google credentials. So, this past week, I wrote my “Offline Vue Boilerplate“. It is meant to be a starting point for the State Parks app and a few other apps that I have kicking around in my head. I figured that this week, we should go over what I wrote.

Overview

The whole point of this “boilerplate” application was for it to be a common starting point for other applications that use Firebase for authentication and a NoSQL database. It uses:

I was using a lot of this stack for work projects, also. It is nice because Firebase is cheap and robust and you don’t need to write any server-side code. Hosting of the front-end code is “cheap-as-chips”, also. The Job Tracker is hosted using Firebase Hosting (which is free on the spark plan) and The Boilerplate App is hosted using Render, which is just as free.

Authentication

I am most proud of how I handled authentication with this app. Here is what the Pinia store looks like:

From your view, you can access {{ user }} to get to the values that came out of the single sign-on (SSO) provider (the user’s name, email address, picture, etc). For this app, I used Google and Microsoft but Firebase Authentication offers a lot of options beyond those two.

https://i0.wp.com/jws.news/wp-content/uploads/2024/03/Screenshot-2024-03-04-at-11.31.08%E2%80%AFAM.png?resize=1024%2C588&ssl=1

Adding Google is pretty easy (after all, Firebase is owned by Google) but adding Microsoft was more difficult. To get keys from Microsoft, you need to register your application with the Microsoft identity platform. Unfortunately, the account that you use for that must be an Azure account with at least a Cloud Application Administrator privileges and it can not be a personal account. The account must be associated with an Entra tenant. This means that you need to spin up an Entra tenant to register the application and get the keys.

The third SSO provider that I was tempted to add was Apple but to do that, you need to enroll in the Apple Developer program, which is not cheap.

Firebase Cloud Firestore

I have become a big fan of Firebase Cloud Firestore over the years (at least for situations where a NoSQL database makes sense). The paradigm that I started playing around with last year involved putting the Firebase CRUD functions in the composable.

Here is an example <script> block from the Job Tracker:

The author of the view doesn’t even need to know that Firebase Cloud Firestore is part of the stack. You might wonder how security is handled.

Here is what the security rule looks like behind the job tracker:

The rule is structured so that any authenticated user can create a new record but users can only read, delete, or update if they created the record.

How I made it into a Progressive Web App (PWA)

This is the easiest bit of the whole process. You just need to add vite-plugin-pwa to the dev dependencies and let it build your manifest. You do need to supply icons for it to use but that’s easy enough.

The Next Steps

I am going to be using this as a stepping-stone to build 2-3 apps but you can look forward to a few deep-dive posts on the stack, also.

Have any questions, comments, etc? Please feel free to drop a comment, below.

[ Cover photo by Barn Images on Unsplash ]

https://jws.news/2024/wrote-a-thing-with-vue-and-firebase/

#CompositionAPI #Firebase #pinia #StateParksApp #VueJs #vuex

mountaincampch, to drupal
@mountaincampch@drupal.community avatar

🦎 MERCÈ, the mascot of has arrived in DAVOS! Don't miss the chance to capture a moment with Mercé and win a free ticket! DrupalCon Europe

🎫 Details: https://drupalmountaincamp.ch/article/capture-moment-merce-win-free-ticket-drupalcon-barcelona-2024

🎟️ Regular tickets still available for : https://drupalmountaincamp.ch/tickets

🤝 We are looking for Volunteers: Join us, contribute, earn drupal.org credits, and make a difference: https://drupalmountaincamp.ch/article/call-volunteers-drupal-mountain-camp-needs-you

mountaincampch, to drupal
@mountaincampch@drupal.community avatar

🤝 Volunteer Alert!

🚀 Join us at and make a direct impact on the event's success!

💪 Earn valuable drupal.org credits! Your contribution matters!

Sign up now:

🔗 Slack: https://app.slack.com/client/T2B5FN14Y/C064USQ13GU

🔗 Volunteer Signup: https://docs.google.com/spreadsheets/d/1SNsWBm9X8e2_sNL0cEExXInrUpkBY5GQLYYhtqdvCU8/edit#gid=2008919609

🔗 Details: https://drupalmountaincamp.ch/article/call-volunteers-drupal-mountain-camp-needs-you

mountaincampch, to drupal
@mountaincampch@drupal.community avatar

🚨 Tomorrow is the LAST DAY to grab your tickets for our exclusive Fondue Night happening on Friday 8th March 2024 in Davos at #DrupalMountainCamp!

🎟️ Secure your spot now: https://drupalmountaincamp.ch/tickets

🏔️ Join our pre-conference in Davos from March 3rd-6th! Enjoy co-working, outdoor activities, and awesome social events in the Swiss Alps.

🔗 Details: https://drupalmountaincamp.ch/drupal-mountain-camp-pre-conference-3rd-6th-march

#FondueNight #ConferenceFun #drupal #opensourcecommunity #opensource #reactjs #vuejs

mountaincampch, to drupal
@mountaincampch@drupal.community avatar

🏔️ The schedule for 2024 is live.

🗓️ Explore the detailed schedule to plan your agenda and make the most of this exciting event: https://event.drupalmountaincamp.ch/drupal-mountain-camp-2024/schedule/

🎟️ Regular tickets are still open: https://drupalmountaincamp.ch/tickets

🇨🇭Come join us for a event full of learning, networking, and fun in the picturesque setting of Davos, Switzerland.

Akryum, to vuejs

Release #vuejs devtools 6.6 with a refreshed UI!

https://github.com/vuejs/devtools/releases/tag/v6.6.0

hashbang, to python French

Nous allons avoir quelques disponibilités bientôt ! Une bonne occasion pour travailler avec de nouvelles clientes !

Qui aurait besoin de soutien de la part de développeureuse #python #django #drf #wagtail #vuejs #odoo #tryton ?

Qui aurait besoin de développements web (site vitrine ou ecommerce, tableau de bord, outil métier, manipulation de données, etc ?) sans contraintes techniques ?

schizanon, to webdev
@schizanon@mas.to avatar

HTMX is just the "back to the land" movement, but for web hippies.

#webDev #htmx #html #javaScript #web #frontend #reactjs #svelte #vue #vuejs #react #hypermedia #hateoas

joe, to vuejs
@joe@toot.works avatar

is sitting at an Irish bar, listening to music from last year's Eurovision, and trying to figure out .

  • All
  • Subscribed
  • Moderated
  • Favorites
  • anitta
  • hgfsjryuu7
  • magazineikmin
  • osvaldo12
  • everett
  • vwfavf
  • ngwrru68w68
  • Youngstown
  • slotface
  • Durango
  • rosin
  • thenastyranch
  • kavyap
  • PowerRangers
  • Leos
  • DreamBathrooms
  • khanakhh
  • GTA5RPClips
  • modclub
  • mdbf
  • ethstaker
  • tacticalgear
  • InstantRegret
  • normalnudes
  • tester
  • cisconetworking
  • cubers
  • provamag3
  • All magazines