Skip to main content

Does Skuid have a context factory or something we could use for generating context? ie. from component to component

We have the deck component and page include… I don’t think I fully understand what you’re asking for. Could you elaborate and possibly give an exact use case? 


When creating a custom component, we’d like to know how to generate the context.

The deck component is somewhat nice, but we are looking to build something a little more sophisticated than what the deck provides. Can we borrow Ben and/or Zack for an hour or two? 😉


Ben and Zack are brilliant, no doubt. I’ll ask and see if I can get a high level answer. 


+1


I would love to pick those guys’ brains. Specifically, this refers to executing an ActionsNode, when creating the “context” object that needs to be passed in as follows:


$a&#46;runActionsNode(actionsNode, component, <b>context</b> || { model: model, item: k&#46;item, row: k&#46;item&#46;row, list: k&#46;item&#46;list, &#47;&#47; required &#47;&#47; if c&#46;attr("role", "button") &#47;&#47; button: c, &#47;&#47; not always required, what does this do???? &#47;&#47; _GUID = b&#46;prototype&#46;id &#47;&#47; &#46;&#46;&#46; so just iD? &#47;&#47; initiatorId: z&#46;editor&#46;_GUID })

The current context at this point is always null, so simply passing it in does nothing and it must be created from scratch… but how? I haven’t been able to figure out what k is in my scenario above… Also, clearly, this whole thing involves setting some custom click event handler on the initiating element… any pointers? somehting we could reuse?


If I had to guess, I’d expect k to be the element that was clicked to initiate the action sequence. Doesn’t element usually have an ‘item’ property?


That makes sense to me. Hmmm …


@Pat If you’re building a custom component that does Deck-like functionality, where you’re iterating over all rows in a Model, and you want to use skuid.actions.runActionsNode() and have it run the actions in context of the particular row that you care about, then just ensure that you are passing in the current row, e.g. your context can be as simple as this:


skuid.actions.runActionsNode(actionsNode, component, {
   model: model, 
   row: row,
});

If you’re trying to do things with “selected Items” or “mass action” type capabilities, that’s more complicated, but I could touch on that a bit more.

Hope that helps.


If only I could intern in the Skuid engineering dept for a week. 


Thanks Zach! that was all I needed. It was really much simpler than I thought…


So I ended up with the following code


$a.runActionsNode(actionsNode, component, context ||<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model: model,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; row: rowID ? model.getRowById(rowID) : null,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initiatorId: initiatorId=event._GUID,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }

Where the row attribute covers the case where context is row-based and the initiatorId is for component-based context cases


@zach could you expand what you offered Pat? 🙂 “If you’re trying to do things with “selected Items” or “mass action” type capabilities, that’s more complicated, but I could touch on that a bit more.”