mobxjs / mobx-state-tree

Full-featured reactive state management without the boilerplate
https://mobx-state-tree.js.org/
MIT License
6.9k stars 639 forks source link

Add a test for debug name #2069

Closed BrianHung closed 10 months ago

BrianHung commented 10 months ago

What does this PR do and why?

Adds a test to https://github.com/mobxjs/mobx-state-tree/pull/2049 Closes https://github.com/mobxjs/mobx-state-tree/issues/2055

Also modifies #2049 to use this.name instead of this.describe, since describe just iterates over children and their types and doesn't actually use name.

const Model = types.model("Name", { value: t.number });
const model = Model.create({ value: 5 });

const array = types.array(Model).create()
const map= types.map(Model).create()

// previous
console.log(getDebugName(model)) // { value: number }
console.log(getDebugName(array)) // { value: number }[]
console.log(getDebugName(map)) // map<string,{ value: number }>

// now
console.log(getDebugName(model)) // Name
console.log(getDebugName(array)) // Name[]
console.log(getDebugName(map)) // Map<string, Name>
coolsoftwaretyler commented 10 months ago

Makes sense! Thanks for the tests, @BrianHung. I'll merge this in and it'll make its way to the 5.2.0 release candidate tonight!