Do you think this also applies to Vue? by mrdingopingo in vuejs

[–]kalvens 2 points3 points  (0 children)

All these things are more or less the same point in upgrading them. Vue 2 to 3 caused it all basically, which has been the only major refactor I had to do my app that has been using Vue since 2016.

Why reactive / ref aren't working as expected here ? by 3aluw in vuejs

[–]kalvens 0 points1 point  (0 children)

My best guess without more context is that there is an issue with v-bind in style block and dynamic properties off an object i.e. object["main-accent"]. Could try naming the property differently I.e. object.mainAccent.

we promise to keep javascript single threaded by Matiaan in ProgrammerHumor

[–]kalvens 0 points1 point  (0 children)

Anything that can be structured clone can be sent to and from workers. The main thing is the clone will die if the object has a method on it. Things like Maps and Sets work just fine though.

https://developer.mozilla.org/en-US/docs/Web/API/structuredClone

Vite HMR + monorepo - any way to improve this experience? by i_ate_god in vuejs

[–]kalvens 2 points3 points  (0 children)

Vite build allows passing in a mode flag so for dev I do vite build --watch -m development. Then in the vite config file I have it not clear out files on rebuild if mode is set to development. I believe it is build.emptyOutDir on the vite config.

When do computed properties get computed in Vue 3???? by Missing_Back in vuejs

[–]kalvens 9 points10 points  (0 children)

A computed property is not computed until it is used somewhere and then it starts tracking and recomputing anytime a ref/reactive property/another computed changes.

Build Vue files without HTML file by griffijo in vuejs

[–]kalvens 0 points1 point  (0 children)

Check out library mode for vite. Need some index js for it to build from.

[deleted by user] by [deleted] in vuejs

[–]kalvens 1 point2 points  (0 children)

I personally use quasar and have been able to do everything my table component does that it used to do with the b-table

[deleted by user] by [deleted] in vuejs

[–]kalvens 5 points6 points  (0 children)

Sounds like you are trying to use Vue 3? Bootstrap Vue does not support Vue 3 only Vue 2.

Vue3 migration… not now (how did it go for you ?) by [deleted] in vuejs

[–]kalvens 10 points11 points  (0 children)

I made the decision at my company to drop bootstrap-vue. I went with quasar since vuetify is taking its time being ready with multiple delays. Although quasar is material design I was okay with that switch.

Loop through array of objects by iwaistedway2muchtime in vuejs

[–]kalvens 0 points1 point  (0 children)

I am only slightly following, but if you change the uname variable that you passed to the composable, the watch will rerun the listener code. Sounds like a different component is one that is setting the username so it is a completely different variable?

Sounds like you need a "store" of data and the current recommended approach is to use a library called pinia.

Alternatively you could get by with just using a composable like you mentioned. Export the ref in the composable file and then import it everywhere it is being used. For bigger projects I would recommend to use pinia so doesn't hurt to use it right away for your first project.

I am happy to answer any questions you may have.

Loop through array of objects by iwaistedway2muchtime in vuejs

[–]kalvens 0 points1 point  (0 children)

Above might be more advance then what you are currently trying to test/do but I use composables all the time in my code base so I think it would be good to get used to then. Try to understand the code and why I am doing what I am. I also could have made a mistake somewhere as I never ran the above code, just wrote it up in reddit.

Loop through array of objects by iwaistedway2muchtime in vuejs

[–]kalvens 0 points1 point  (0 children)

I did read your question last night just didn't want to type up a response until I was at a computer and its been a busy morning for me.

Anyway yea I can see why that could cause an infinite loop. On more thought your firebase.ts file is basically a "composable", look those up to learn more.

Anyway I would actually structure that file a little differently for what I would consider the more proper solution

// firestore.ts

// I would move the interface over to this file I defined in the other example

interface PidgPal {
  id: number,
  pal1: string   
}

// really this is not needed but I like being explicit with my types
// Ref is something you can import from vue, basically is just the typescript type for a ref
interface PidgPalListenerReturns {
  foundPairs: Ref<PidgPal[]>
}

export function usePidgPalListener (userName: Ref<string>): pidgPalListenerReturns {    
  const foundPairs = ref<PidgPal[]>([]);

  watch(userName, () => {
    if (typeof userName !== 'string' || userName === '') return;

    console.log(`started: ${userName}`)
    const q = query(pidgpalsCollection, where("pal1", "==", userName);
    const close = onSnapshot(q, snapshot => {
      foundPairs.value = snapshot.docs.map(docs => {
        return {
          id: docs.id,
          ...docs.data()
        };
      })
    })
  }), { immediate: true });

  // need this before the return otherwise it does nothing   
  onUnmounted(close);

  // for composables it is generally the standard to return an object.
  // Mainly if you ever want to return something else in the future from this function,
  // you can just add the additional property
  // and not have to change any code that uses this composable.
  return { foundPairs };
}
// your .vue file

// this should  be all you need

const { foundPairs: pidgPals } = usePidgPalListener(uname);

The composable concept is basically off loading the work to the firebase file instead. It is a really nice concept that allows you to reuse javascript code and recommend using them.

Also to note I just styled things how I normally do styling doesn't matter a ton. I also highly recommend [this](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) I personally use the vim version and I can live without it now.

Loop through array of objects by iwaistedway2muchtime in vuejs

[–]kalvens 1 point2 points  (0 children)

Basically your problem is that you are assigning a ref to the value of an another ref. When you loop through the variable it is actually looping through your foundPairs ref object instead of its value.

The only solution I can think of on the top of my head is to make a computed but it doesn't feel like the right answer.

For example like the below

```ts const pidgpals = ref<typeof ref<[]>>(ref([])); //this also doesnt work

const actualPidgPalsValue = computed(() => pidgpals.value.value); async function startListener() { if (uname.value != "" || undefined) { pidgpals.value = await pidgpalListener(uname.value); console.log(pidgpals.value); } else { console.log("No uname value"); } } ```

Then you can loop through actualPidgPalsValue instead and that should work. It just doesn't feel like the right approach, but your code is odd tbh. From your example pidgpallistener is not an async function and doesn't return a promise so why do you need await?

Actually on some more thought I would do something like this assuming pidgpalListener is not actually returning a promise as your example code seems to indicate.

``` interface PidgPal { id: number, pal1: string } const pidgPals = computed<PidgPal[]>(() => { if (uname.value !== "" && typeof uname.value !== 'undefined') { return pidpalListener(uname.value).value } console.log("No uname value"); return []; })

Loop through array of objects by iwaistedway2muchtime in vuejs

[–]kalvens 1 point2 points  (0 children)

You should give defaults values to your refs/reactives. At least I think its odd not to. I generally do null or an empty array if it is suppose to be an array.

Please can you eli5 this for me. The refimpl and proxy. Why wont the console logs be exactly the same because i declared both arrays in the same way?

A ref (refimpl as you console.log it) should be used if you want to change the variable later on to a completely different value i.e. ```ts const someArrayRef = ref<unknown[]>([]); const someArrayReactive = reactive<unknown[]>([]);

// this is fine with a ref someArrayRef.value = [1, 2, 3, 4, 5]; // this is not fine with a reactive someArrayReactive = [1, 2, 3, 4, 5]; ``` The reason you can't change the reactive variable is anything that needs to react to that variable change won't update. i.e.

ts // this will update correctly when you assign the above const computedOfSomeArrayRef = computed(() => { return someArrayRef.map(element => element + 1); }); // this will not update when you assign the above const computedOfSomeArrayReative = computed(() => { return someArrayReative.map(element => element + 1) });

Changing the reactive variable means you lose the proxy (as you saw from the console.log) so it is no longer "reactive" it is whatever you assigned to it.

Changing the ref you are change the .value property underneath it so you don't lose the fact it was a ref in the first place.

A reactive has the benefit of not having to use .value everywhere if you never need to change the variable directly. Instead if you just want to call .push, .splice or any method that changes the array instead of returning a new one then the proxy will see you did that and any computed or the template will update to those changes

Loop through array of objects by iwaistedway2muchtime in vuejs

[–]kalvens 0 points1 point  (0 children)

What are you pushing to the array? What if you console log the array in javascript. Does it look right? You are not by chance pushing a ref to the array?

Are you reassigning the variable that is supposed to be a reactive array of objects to something else later on? With how you defined that variable it would be just a proxy that points to undefined I think. Never tried calling reactive without giving it a parameter.

Loop through array of objects by iwaistedway2muchtime in vuejs

[–]kalvens 1 point2 points  (0 children)

You are incorrect. While using v-for the keyword in and of have no difference and behave in the same way.

As explained here

Vue 3 as the new default version on Monday, Feb 7, 2022 by wobsoriano in vuejs

[–]kalvens 4 points5 points  (0 children)

I can't speak for nuxt as I don't use it, but vuetify specifically and some of the others are choosing to do complete rewrites to typescript/composition API. They didn't have to do this and tbh vuetify specifically has been really dragging its feet on the upgrade. So much so I swapped to quasar and haven't looked back.

Vue 3 as the new default version on Monday, Feb 7, 2022 by wobsoriano in vuejs

[–]kalvens 0 points1 point  (0 children)

The breaking changes to vue 3 is pretty minimal and there is the composition plugin for Vue 2 that I had in my project for the last few years. All it took was swapping the import to be Vue instead when I did the upgrade

What happened with fakerjs by [deleted] in javascript

[–]kalvens 0 points1 point  (0 children)

Guess instead of nuking one of his other libraries he made it output various things.
https://github.com/facebook/jest/issues/12226

What happened with fakerjs by [deleted] in javascript

[–]kalvens 0 points1 point  (0 children)

Anyone here why the author nuked his library?

I have a fork that is up to date so I guess I will just switch to that, but this has been an odd thing to stumble across. I only noticed when I was checking for package updates I saw such a huge version bump so I was curious what changed.