How to use the backbone.marionette.Object function in backbone

To help you get started, we’ve selected a few backbone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kilbot / WooCommerce-POS / assets / js / src / lib / config / service.js View on Github external
var Mn = require('backbone.marionette');
var Radio = require('backbone.radio');
var app = require('./application');
var _ = require('lodash');

module.exports = app.prototype.Service = Mn.Object.extend({
  constructor: function(options) {
    options = options || {};

    if (this.channelName) {
      this.channel = Radio.channel(_.result(this, 'channelName'));
    }

    // add reference to the app, like old Marionette.Module
    if(options.app){
      this.app = options.app;
    }

    Mn.Object.apply(this, arguments);
  },

  start: function(){
github DefinitelyTyped / DefinitelyTyped / backbone.marionette / backbone.marionette-tests.ts View on Github external
template() {
            return '<h1>' + this.model.getName() + '</h1> <button class="destroy">Destroy Me</button>';
        }
    };


    class MainRegion extends Marionette.Region {
        constructor() {
            super();
            this.el = '#main';
        }
    }


    class MyObject extends Marionette.Object {
        name: string;
        options: any;

        constructor() {
            super();
            this.name = 'Adam';

            this.options = {
                name: 'Foo'
            };

            this.on("before:destroy", () =&gt; {
                console.log("before:destroy");
            });
        }
github Laverna / laverna / app / scripts / components / fileDialog / Controller.js View on Github external
import Mn from 'backbone.marionette';
import _ from 'underscore';
import Radio from 'backbone.radio';
import View from './View';
import deb from 'debug';

const log = deb('lav:components/fileDialog/Controller');

/**
 * File dialog controller.
 *
 * @class
 * @extends Marionette.Object
 * @license MPL-2.0
 */
export default class Controller extends Mn.Object {

    onDestroy() {
        log('destroyed');

        if (this.promise) {
            this.promise.resolve(null);
            this.promise = null;
        }
    }

    /**
     * Initialize the dialog view.
     *
     * @returns {Promise}
     */
    init() {
github jamiebuilds / marionette-wires / src / common / service.js View on Github external
constructor() {
    if (this.channelName) {
      this.channel = Radio.channel(_.result(this, 'channelName'));
    }

    Marionette.Object.apply(this, arguments);
  },
github fs / backbone-base / app / scripts / controllers / articles_controller.js View on Github external
import Marionette from 'backbone.marionette';
import App from 'application';
import ArticleLayout from 'views/article/layout';
import ArticlesLayout from 'views/articles/layout';
import Article from 'models/article';
import Articles from 'collections/articles';

export default class ArticlesController extends Marionette.Object {
  index(page) {
    const articles = new Articles();

    articles.fetchByPage(page).then(() => {
      App.layout.mainRegion.show(new ArticlesLayout({
        page,
        collection: articles
      }));
    });
  }

  show(page, id) {
    const article = new Article({ id });

    article.fetch().then(() => {
      App.layout.mainRegion.show(new ArticleLayout({ model: article }));
github scott-w / reps-js / app / base / controller.js View on Github external
import Mn from 'backbone.marionette';
import _ from 'underscore';

import root from '../root';


/** Provides a base controller that oversees interaction with the root view.
    To use this, you must extend the controller with:
      layoutView: The base View that owns the sub-app
      layoutOptions (optional): Any options to pass into instantating layoutView
*/
export const BaseController = Mn.Object.extend({
  mainView: 'main',

  /** Returns whether the current base view is the view being displayed
  */
  showingMyView: function() {
    const view = root.getChildView('main');
    const cid = this.getOption('indexCid');

    if (_.isUndefined(cid)) {
      return false;
    }
    return view.cid === cid;
  },

  /** Forcibly shows this controller's base layout and returns a reference to
      it.
github highvalley-systems / wargames / _scripts / controller / multiplayer.js View on Github external
import Marionette from 'backbone.marionette';
import _ from 'underscore';
import PlayerView from '../view/player';
import Missile from '../model/missile';
import Player from '../model/player';

const Multiplayer = Marionette.Object.extend({

  initialize: function(options) {
    this.map = options.map;
    this.info = options.info;
    this.count = 0;

    this.player = options.player;
    this.listenTo(this.player, 'located', this.registerLocation);

    this.missiles = options.missiles;
    this.listenTo(options.missiles, 'launch', this.sendMissile);

    this.socket = this.setupSocket(options.url);

    var that = this;
github Laverna / laverna / app / scripts / components / linkDialog / Controller.js View on Github external
import Mn from 'backbone.marionette';
import _ from 'underscore';
import Radio from 'backbone.radio';
import View from './views/View';
import deb from 'debug';

const log = deb('lav:components/linkDialog/Controller');

/**
 * Link dialog controller.
 *
 * @class
 * @extends Marionette.Object
 * @license MPL-2.0
 */
export default class Controller extends Mn.Object {

    /**
     * Radio channel.
     *
     * @prop {Object}
     */
    get channel() {
        return Radio.channel('components/linkDialog');
    }

    /**
     * Notes collection channel.
     *
     * @prop {Object}
     */
    get notesChannel() {
github misantronic / rbtv.youtube / app.old / overrides / marionette.js View on Github external
};

Marionette.View = View.extend(MarionetteViewPrototype);

/**
 * RADIO - Marionette.Object
 */

Marionette.Object = function () {
    MarionetteObject.apply(this, arguments);

    radioMixin.call(this);
};

Marionette.Object.extend = Marionette.extend;
Marionette.Object.prototype = MarionetteObjectPrototype;

/**
 * Optimize attachElContent
 */

function attachElContent(html) {
    if (_.isString(html)) {
        this.$el[0].innerHTML = html;
    } else {
        this.$el.html(html);
    }

    return this;
}

Marionette.ItemView.prototype.attachElContent = attachElContent;
github omahajs / generator-omaha / generators / webapp / templates / example.controller.js View on Github external
define(function(require, exports, module) {
    'use strict';

    const Mn = require('backbone.marionette');

    /**
     * @name ExampleController
     * @description Example controller
     * @constructor
     * @extends Marionette.Object
    **/
    const ExampleController = Mn.Object.extend({
        //controller code goes here
    });

    module.exports = ExampleController;
});