Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ampersand-grouped-collection-view

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-grouped-collection-view

Render the items in a collection, where items may be grouped in batches (such as a list of chats grouped by sender)

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
62
Maintainers
1
Weekly downloads
 
Created
Source

ampersand-grouped-collection-view

Renders a collection of items that are clustered in groups, such as how chat messages can be displayed grouped by sender.

Part of the Ampersand.js toolkit for building clientside applications.

Install

npm install ampersand-grouped-collection-view

Example

var View = require('ampersand-view');
var GroupedCollectionView = require('ampersand-grouped-collection-view');


var view = new GroupedCollectionView({
    el: someDOMElement,
    collection: messagesCollection,

    itemView: View.extend({
        template: '<div><p data-hook="msg-body"></p><span data-hook="msg-time"><span></div>',
        bindings: {
            'model.body': {
                type: 'text'
                hook: 'msg-body'
            },
            'model.timestamp': {
                type: 'text',
                hook: 'msg-time'
            }
        }
    }),
    groupView: View.extend({
        template: '<div><img data-hook="avatar"/><ul data-hook="messages"></ul></div>',
        bindings: {
            'model.avatar': {
                type: 'attribute',
                name: 'src',
                hook: 'avatar'
            }
        },
        render: function () {
            this.renderWithTemplate();
            // The `groupEl` property is special for group views. If provided, item
            // views will be appended there instead of on the root element for the
            // group view.
            this.cacheElements({
                groupEl: '[data-hook=messages]'
            });
        }
    }),

    groupsWith: function (model, prevModel, currentGroup) {
        // Used to determine when a new group is needed.
        // Return `true` if `model` belongs to the same group
        // as `prevModel`.
        // The current group is also available for comparison.
        return model.sender.id === prevModel.sender.id;
    },
    prepareGroup: function (model, prevGroup) {
        // Prepare a Group model based on the Item model
        // that triggered the group's creation.
        // The previous group model is also provided.
        return model.sender; 
    }
});

FAQs

Package last updated on 22 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc