Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play with components #19

Closed
Swizz opened this issue Apr 21, 2016 · 5 comments
Closed

Play with components #19

Swizz opened this issue Apr 21, 2016 · 5 comments

Comments

@Swizz
Copy link

Swizz commented Apr 21, 2016

Hi,

I want to use ember-dragula in a project.

But, I use dragula to copy element from a deck to a workbench.
Each element is an ember component and deal with own actions.

Unfortunatly, dragula copy all the DOM without the component logic.
When I call an action from a component inside the workbench, the component emitter is finally the deck one.

So, How can I use ember-dragula to create an unique component after copying ?

Thanks for advance,

@pksjce
Copy link

pksjce commented Apr 21, 2016

Hi,

Can you post your code?
In dragula, you have access to drag/drop events. Maybe you could use them to copy the component instances?

@Swizz
Copy link
Author

Swizz commented Apr 21, 2016

The code is really basic as

{{#ember-dragula-container id="playground"}}
{{/ember-dragula-container}}

{{#ember-dragula-container}}
    {{draggable-table title="SomeTitle"}}
{{/ember-dragula-container}}

And the DraggableTable component as own template and actions.

So when I drag/drop the DraggableTable to the playground, it whill copy the dom of the component, not the component itself.

So, call action from the DraggableTable component iside the playground will call infact action inside the original one.


Drap/drop events give only dom elements. And I do not know the way to retrieve a component instance from a dom element.


So, I am considering to play with lists, and use component only for visual stuff.
And using events to serialize/unserialize datas to dom.

@pksjce
Copy link

pksjce commented Apr 21, 2016

Would it help if I passed the ember object instance as argument for the
events?

Regards,
Pavithra.K

On Thu, Apr 21, 2016 at 8:10 PM, Quentin Gerodel notifications@github.com
wrote:

The code is really basic as

{{#ember-dragula-container id="playground"}}
{{/ember-dragula-container}}

{{#ember-dragula-container}}
{{draggable-table title="SomeTitle"}}
{{/ember-dragula-container}}

And the DraggableTable component as own template and actions.

So when I drag/drop the DraggableTable to the playground, it whill copy
the dom of the component, not the component itself.

So, call action from the DraggableTable component iside the playground

will call infact action inside the original one.

Drap/drop events give only dom elements. And I do not know the way to

retrieve a component instance from a dom element.

So, I am considering to play with lists, and use component only for visual
stuff.
And using events to serialize/unserialize datas to dom.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#19 (comment)

@Swizz
Copy link
Author

Swizz commented Apr 21, 2016

It depend of the Ember object we talk about.

In this case, I request the el parameter of events.

@Swizz
Copy link
Author

Swizz commented Apr 25, 2016

//app/utils.js

export const getComponentFromId = (id) => {
  return FrontEmber.__container__.lookup('-view-registry:main')[id];
};

export const getComponentFromEl = (el) => {
  return getComponentFromId(el.id);
};
//app/editor/controller.js

//[...]

    didDrop(el, target) {
      let table = getComponentFromEl(el),
          playground = getComponentFromEl(target);

      playground.tables.addObject(table.model);
      Ember.$(el).remove();
    }

//[...]

Give me all I need.

Thanks for your time.

@Swizz Swizz closed this as completed Apr 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants