jd-solanki / anu

Anu - DX focused utility based vue component library built on top of UnoCSS & VueUse ⚡️🔥

Home Page:https://anu-vue.netlify.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[useGroupModel] and [AList]: Support dynamic items

jsmnbom opened this issue · comments

commented

Currently it seems that AList does not support giving it dynamic items.

In AList useGroupModel gets passed options based on a mapped expression of props.items. This however makes it lose any reactivity it had.

I've tried to fix this myself, but due to how useGroupModel works and such, it turned out to be way more complicated than i thought. I tried here: main...jsmnbom:anu:gross-alist but as the branch name suggests, its really really gross (and uses a seperate useGroupModel, tho that should be easy enough to integrate back.)

Other issues I might potentially have found that should be taken into account when fixing this:
useGroupModel has no idea what the model value is. It doesn't get it passed, and if it updates, it also has no idea.
AList also doesn't seem to support bare string[] as items??

I replaced a part of useGroupModel with hook, so that we can operate Set more conveniently

export function useSet<T>(setTarget:Set<T>):{value:T}{
  let back:Set<T> = setTarget;
  const updateSet=():any=>{
    return Object.defineProperty({},"value",{
      set(val:T){
        if(back.has(val)){
          back.delete(val)
        }else{
          back.add(val)
        }
      },
      get(){
        return [...back]
      }
    })
  }
  return updateSet()
}

usage:

let s = useSet(new Set());
s.value = 32
console.log(s.value) // [ 32 ]
s.value = 34
console.log(s.value) // [ 32, 34 ]
s.value = 32
console.log(s.value) // [ 34 ]
commented

That doesn't apply here? My issue persists even without using sets (multi=false).

Hi, @jsmnbom @jingyuexing can you please try with the latest release?

commented

I tested it with commit 4073c1c originally.
You are however, completely right and this works as it is supposed to. My issue is a completely different one that i just misdiagnosed. I've submitted #151.