Code Monkey home page Code Monkey logo

Comments (6)

dustinboston avatar dustinboston commented on July 19, 2024

@vtsurka You would call publish with some extra data:

// task list
sandbox.publish('task', 'detail', id);

// task detail
sandbox.subscribe('task', 'detail', function (caller, id) {
  // Do things with id
});

If you check out the console when you run Aura you will see a bunch of messages like "Todos-bootstrap message from from: controls". Each of those messages are being published from one widget and subscribed by another widget. You just have to add the additional data to the call.

from aura.

dustinboston avatar dustinboston commented on July 19, 2024

@addyosmani I'd like to add another button to the controls that publishes extra data. If you agree, I'll commit.

from aura.

addyosmani avatar addyosmani commented on July 19, 2024

Fully agree. Feel free to :)

from aura.

dustinboston avatar dustinboston commented on July 19, 2024

Done.

from aura.

vtsurka avatar vtsurka commented on July 19, 2024

I expected send the id of model, but we have model 'Task' they use in widgets: TaskList, TaskDetailed.
Where i must store this model if they uses in both widgets.

I don't want duplicate model ;(

from aura.

vtsurka avatar vtsurka commented on July 19, 2024

I need generate page like this

When i click on link expand, will show detailed todo under row.

Sketch

So i have todos(as like demo app) i add method show /widgets/views/todos.js

        events: {
                        //... other events
            'click .view': 'show',
        },

        //Show detailed info about task
        show: function() {
            sandbox.widgets.start('detailed',this.$el);
            sandbox.widgets.publish('todo-detailed',this.model);
        },

And i create widget detailed

Widget main.js

define(['sandbox', './views/app'], function (sandbox, AppView) {

    return function (element) {
        var view = new AppView({
            el: sandbox.dom.find(element)
        });     
               return view;

        sandbox.subscribe('todo-detailed', 'detailed', function (todo) {
            //apply model
            view.model = todo;          

        });
    };

});

View

define(['sandbox', 'text!../templates/detailed.html'], function (sandbox, template) {

    var AppView = sandbox.mvc.View({

        template: sandbox.template.parse(template),


        events: {
            'click .save': 'save',
            'click .start': 'start',
            'click .stop': 'stop'
        },
        // At initialization we bind to the relevant events on the `Todos`
        // collection, when items are added or changed. Kick things off by
        // loading any preexisting todos that might be saved in *localStorage*.
        initialize: function () {
            sandbox.widgets.start('todo-history','#todo-history');
            sandbox.widgets.start('todo-comment','#todo-comment');
        },

        render: function() {            
            this.$el.html(this.template(this.model.toJSON()));
        }

    });

    return AppView;

});

Is it right way to organize widget like this?

from aura.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.