define [
    '../core'
    'tpl!templates/context/actions.html'
], (c, templates...) ->

    templates = c._.object ['actions'], templates


    # Provides a set of actions for manipulating a ContextModel object
    class ContextActions extends c.Marionette.ItemView
        template: templates.actions

        ui:
            count: '.count'

        events:
            'click [data-role=remove]': 'clickRemoveAll'

        modelEvents:
            'change:count': 'renderCount'

        serializeData: ->
            attrs = c._.clone(@model.attributes)
            delete attrs.json
            attrs.count = c.utils.prettyNumber(attrs.count)
            return attrs

        renderCount: (model, value, options) ->
            @ui.count.html(c.utils.prettyNumber(value))

        clickRemoveAll: ->
            @model.manager.remove()


    { ContextActions }

define [
    '../core'
    'tpl!templates/context/actions.html'
], (c, templates...) ->

    templates = c._.object ['actions'], templates


    # Provides a set of actions for manipulating a ContextModel object
    class ContextActions extends c.Marionette.ItemView
        template: templates.actions

        ui:
            count: '.count'

        events:
            'click [data-role=remove]': 'clickRemoveAll'

        modelEvents:
            'change:count': 'renderCount'

        serializeData: ->
            attrs = {}
            if @model?
                attrs = c._.clone(@model.attributes)
                delete attrs.json
                attrs.count = c.utils.prettyNumber(attrs.count)
            return attrs

        renderCount: (model, value, options) ->
            @ui.count.html(c.utils.prettyNumber(value))

        clickRemoveAll: ->
            @model.manager.remove()


    { ContextActions }

Check if model is defined before cloning its attributes
Check if model is defined before cloning its attributes

Previously, if the context(@model) was empty then the `attrs = c._.clone(...)` line would fail with an error involving the attempt to access the attributes property of an undefined object. This code checks if the model is defined before cloning and updating the count and returns the empty object if model is not defined.