hybridsjs / hybrids

Extraordinary JavaScript UI framework with unique declarative and functional architecture
https://hybrids.js.org
MIT License
3.05k stars 85 forks source link

The "store(Model, { id: value })" descriptor does not resolve "id" correctly to the model instance. #240

Closed Qsppl closed 7 months ago

Qsppl commented 7 months ago

https://github.com/hybridsjs/hybrids/blob/36df51a77b5baad2a179bb16fb8e1ff6010624af/src/store.js#L1518

const resolveId = options.id
    ? options.id
    : (host, value) => {
        if (value !== null && typeof value === "object") return value.id;
        return value ? String(value) : undefined;
      };

The resolveId function resolves 0 to undefined, but expects 0 to resolve to "0". This causes the error TypeError: Provided model definition requires non-empty id: "undefined". Example: https://codepen.io/qsppl/pen/rNbyOrm?editors=1010

smalluban commented 7 months ago

Thanks for raising this up, fixed in https://github.com/hybridsjs/hybrids/commit/bbf280b788061f43467a63c923aa48d555f17771

Plase update to v8.2.12

Qsppl commented 7 months ago

Thank you

Qsppl commented 7 months ago

Solving this error resulted in another error that I can't find.

The component with model { id: 0, ... } now receives a model, but then loses it: https://codepen.io/qsppl/pen/jORBqed?editors=1010