Git Product home page Git Product logo

Comments (9)

rhwilr avatar rhwilr commented on May 12, 2024 1

Hi @RomainLanz, glad you like it 😃
You make some excellent points here, I really like your proposals 👍

The only one I feel needs a bit of clarification is "4. Defines the transformer for collection and item".
I personally never had the need to define a different schema for a collection then for an item. The transform method describes how a single item is represented and a collection is just a selection of those items. This way you can rely on that you will get the same result when you request an item as when you get that same item as part of a collection.

I'd be interested in your use case and your view on this.

Otherwise, really like your proposals and would happily accept PRs for them. Unfortunately, I'm currently really busy with work for the university, so I won't be able to spend much time on it in the next few months. But if you are able to do some work that would be awesome!

from adonis-bumblebee.

rhwilr avatar rhwilr commented on May 12, 2024 1

I like this. It is definitely a more flexible way of implementing this.
I don't see anything preventing us from implementing this, though I haven't given it too much thought.

I'm sure you will come up with something awesome! Go ahead. 😃

from adonis-bumblebee.

RomainLanz avatar RomainLanz commented on May 12, 2024 1

That's awesome!

Also, it seems that the code I've added to directly use the IoC instead of passing an instance isn't working.

I'll need to take a look.

from adonis-bumblebee.

RomainLanz avatar RomainLanz commented on May 12, 2024

Otherwise, really like your proposals and would happily accept PRs for them. Unfortunately, I'm currently really busy with work for the university, so I won't be able to spend much time on it in the next few months. But if you are able to do some work that would be awesome!

Sure I'll work on those PRs during this week.

I'd be interested in your use case and your view on this.

I can understand the point of view that you define a schema for an item and a collection is a list of this item.

My use case is the item when requested alone, give a lot more information than when it's requested via a list.

As a real example, I'm creating a CMS that can handle an article in a different language.

Calling /articles gives me the following:

[
  {
    id: 1,
    headline: '...',
    thumbnail: '...',
    featured_thumbnail: '...',
    translations: ['fr', 'en']
    published_at: '...',
    featured: false,
  },
  ...
]

In the meanwhile, calling /articles/1 gives me a lot more information:

{
  id: 1,
  headline: '...',
  description: '...',
  body: '...',
  thumbnail: '...',
  featured_thumbnail: '...',
  translations: ['fr', 'en']
  published_at: '...',
  sources: [...],
  ...
}

Therefore, having only one transformer isn't possible because the schema change between one item or a collection of this item.

from adonis-bumblebee.

rhwilr avatar rhwilr commented on May 12, 2024

Sure I'll work on those PRs during this week.

You're awesome 👍 😃

As to your example, I did have a similar case with blog posts once where I also didn't want the body of the post in the collection view. My solution was to use an availableInclude for the body. This allowed me to keep a consistent API between the item and collection, while still making it possible to load the body over the same API if needed.

But I can see how it can be useful in some cases. I would be willing to accept a PR if it keeps the existing API where transform is used for items and collections and if needed a transformCollection and transformItem method can be defined to be more specific.

from adonis-bumblebee.

RomainLanz avatar RomainLanz commented on May 12, 2024

After more reflexion, I'm thinking about having a variants array that let us create many transform method.

By default transform() is called, but you could ask for a specific variant which will call transformNameOfTheVariant().

This could also help when you have two different output for casual and admin.

from adonis-bumblebee.

rhwilr avatar rhwilr commented on May 12, 2024

@RomainLanz I finally have a few hours of free time, I think I'll give feature 4 "multiple transformers" a try. 😃

from adonis-bumblebee.

rhwilr avatar rhwilr commented on May 12, 2024

For everyone whos interested in checking out these new features: The updated documentation can be found in the next branch and a beta version for 2.0.0 is available on npm.

Feedback and bug reports are highly appreciated.

from adonis-bumblebee.

rhwilr avatar rhwilr commented on May 12, 2024

Since all features proposed here are now implemented, I'll close this issue. Please open a new issue to report bugs in the beta version.

from adonis-bumblebee.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.