Comments (9)
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.
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.
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.
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.
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.
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.
@RomainLanz I finally have a few hours of free time, I think I'll give feature 4 "multiple transformers" a try. 😃
from adonis-bumblebee.
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.
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)
- Error: Transformer is not a function HOT 3
- Suggestion: create a "class generator" for the Adonis CLI HOT 2
- Namespaced Transformers Support HOT 1
- How to access to pivot table data? HOT 5
- JSONAPI compliant serializer HOT 3
- Includes don't work for many to many relations HOT 5
- Access transform object from services HOT 2
- How to use in websocket controller HOT 1
- availableInclude not working as expected HOT 2
- A transformer must be a function or a class extending TransformerAbstract HOT 1
- How to change the status code on returning the transformed data? Like for a transform with pagination send 206 http status code.
- Include underscore not working HOT 3
- A transformer must be a function or a class extending TransformerAbstract HOT 6
- [Question] Accessing Manager from inside Transformer HOT 4
- Honor setHidden and setVisible HOT 2
- Is v5 planned for this package? HOT 8
- Chain Transformers with Routes
- Fail load relation on empty value fkey column when use include in transformer
- property transform does not exits in ctx
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adonis-bumblebee.