-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data v4 #410
Data v4 #410
Conversation
# Conflicts: # CHANGELOG.md # src/Resolvers/DataFromSomethingResolver.php # src/Support/DataMethod.php # src/Transformers/DataCollectableTransformer.php # src/Transformers/DataTransformer.php # tests/DataTest.php
# Conflicts: # CHANGELOG.md # src/Support/DataProperty.php # src/Support/DataType.php # tests/Support/DataTypeTest.php # tests/Support/TypeScriptTransformer/DataTypeScriptTransformerTest.php
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
1296f37
to
83c46bf
Compare
… into beyond-data
Wanted to give a heads up on fa428ce#diff-ae2f481eb5439ef575f8131c7b806281fcdafe257235badb387a90da175fea7aR40. It's not really mentioned in the upgrade guide, but it was a big breaking change that took a bit of work to get straightened out. Maybe it's worth mentioning, but I'd also like to get some feedback on it. Basically we have a lot of models with extra custom attributes (methods). This new functionality triggers/uses ALL of the optional attributes (not included in E.g. in one case, we have a data object with only a name and a slug: <?php
declare(strict_types=1);
namespace Shared;
use Spatie\LaravelData\Data;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;
#[TypeScript]
final class ExampleData extends Data
{
public function __construct(
public readonly string $name,
public readonly string $slug,
) {}
} And we create it from some models: ExampleData::collect($models) In some cases, we can fix it by parsing the Eloquent collection to an array instead: ExampleData::collect($models->toArray()) But that sometimes introduces other problems because of them being parsed to arrays. This isn't always viable since Is this still the correct way of creating collections though? Followed the upgrade guide and new documentation. From an external point of view, you'd expect it to just do Another small thing is that passing |
That's because we try to normalize the data structure to an array before doing anything on it. Since it takes quite a while and a lot of checks before we know what properties are required. Additionally, as you mentioned, based upon the kind of structure provided additional things should happen like with model dates. I once had an idea how we could build it so that we don't require normalizers anymore, but that is such a big change that we need a v5. Take a look at the I wouldn't mind a PR which allows users to enable or disable certain parts of the normalizer. As for collecting |
Thanks for the explanation, makes sense of course. For now we've reverted the upgrade because we found a few bugs or changes that were too much to handle (i.e. the above, nested data isn't parsed to data objects anymore if you use PHPDoc annotations for collections, objects are now arrays when transforming to TypeScript), but we'll look into it later and see if we can reproduce it to perhaps open issues. |
We are having the same difficulties with the changes to collections in v4, which is why we are staying on v3. |
#407