Examples

Components built with Simple view usually have structure similar to one bellow:


            var MyView = SimpleView.extend({

                defaults: {
                    titleSelector: '.title'
                },

                initialize: function(options) {
                    this.options = $.extend({}, this.defaults, options);
                },

                events: {
                    'click .text': 'updateView',
                    'one:click .toggleBtn': function(e) { // one time events
                        console.log($(e.target).text());
                    },
                    'click {{this.options.titleSelector}}': 'play', // dynamic selector
                    'resize window': 'updateView', // window events
                    'one:keyup document': 'handleKeyup'
                },

                updateView: function() {
                    // update logic
                },

                handleKeyup: function() {
                    // some update logic
                }
            });
        

Subclass and add sub views like so:


            var MyViewSubClass = MyView.extend({
                someExtraMethod: function(){
                    this.addView(new MyAnotherView({$el: this.$('.subView')}))
                }
            });

            var MyAnotherView = SimpleView.extend({
                initialize: function() {
                    // initializing logic
                }
            });

            var view = new MyViewSubClass({$el: '.test'})
            view.remove(); // will remove all attached sub views as well