Skip to content

Pass index to custom callback in controllers binding #5268

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

Closed
oskarwrobel opened this issue Oct 26, 2016 · 5 comments
Closed

Pass index to custom callback in controllers binding #5268

oskarwrobel opened this issue Oct 26, 2016 · 5 comments
Labels
package:ui type:question This issue asks a question (how to...).

Comments

@oskarwrobel
Copy link
Contributor

Right now is:

        controllers.bind( data ).as( ( item, locale ) => {
            if ( !item.foo ) {
                return null;
            } else if ( item.foo == 'bar' ) {
                return new BarController( ..., BarView( locale ) );
            } else {
                return new DifferentController( ..., DifferentView( locale ) );
            }
        } );

and I'm thinking about something like this:

        controllers.bind( data ).as( ( item, locale, index ) => {
            if ( item.inactive ) {
                return null; // Does not increment index.
            } else if ( index < 10 ) {
                return new Controller( ..., FullView( locale );
            } else {
                return new Controller( ..., CompactView( locale );
            }
        } );

Question is what will happen when new item will be added at the top of already rendered collection?

@oleq
Copy link
Member

oleq commented Nov 9, 2016

To work like this, the entire ViewCollection would need to be re–rendered because current implementation assumes that once added, the View is immutable – it does not change it's class as long as it belongs to the VC.

It is possible to implement it, but the question is do we really need it? Could an additional controllers.on( 'add', ... ) listener handle a necessary transformation?

@oleq
Copy link
Member

oleq commented Nov 18, 2016

This issue is still valid but for ViewCollection because Controller class is gone now (#95).

@oleq
Copy link
Member

oleq commented Apr 20, 2018

@oskarwrobel
Copy link
Contributor Author

Nope. But I'm not sure if this is something that we need anymore. CollaborativeComments uses something similar because collapsed comment displays only the first and the last comment but there is an additional view between those comments:

Models:                Views:
[ Comment 1 ]
[ Comment 2 ]          [ Comment 1 ]
[ Comment 3 ]  ----->  [ Additional view counter ]
[ Comment 4 ]          [ Comment 5 ]
[ Comment 5 ]

And this is handled by an additional collection that is between collection of all models and view collection:

All models:            Filtered models:       Views:
[ Comment 1 ]
[ Comment 2 ]          [ Comment 1 ]          [ Comment 1 ]
[ Comment 3 ]  ----->  [ Counter   ]  ----->  [ Counter ]
[ Comment 4 ]          [ Comment 5 ]          [ Comment 5 ]
[ Comment 5 ]

@Reinmar
Copy link
Member

Reinmar commented Jul 16, 2019

I assume this is not relevant anymore.

@Reinmar Reinmar closed this as completed Jul 16, 2019
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-ui Oct 9, 2019
@mlewand mlewand added resolution:solved type:question This issue asks a question (how to...). package:ui labels Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:ui type:question This issue asks a question (how to...).
Projects
None yet
Development

No branches or pull requests

4 participants