teact icon indicating copy to clipboard operation
teact copied to clipboard

may need a companion to pureComponent to push a given child to stack

Open leiyangyou opened this issue 8 years ago • 2 comments

ran into a usecase where I need to wrap a component before pushing the component onto the stack

leiyangyou avatar Jan 12 '17 01:01 leiyangyou

Let me reopen this, and elaborate a bit on the usecase.

The scenario I have is this, when using react-dnd, I need to sometimes wrap a child inside a decorator.

For example connectDragSource, this is what I have to do with just crel and pureComponent

 T.crel ->
    connectDragSource(do T.pureComponent ->
       T.div
       T.div
    )

Not too bad, what i ended up doing is however this

T.use((teact)->
  T.push = (contents)->
    teact.stack?.push contents
    return contents

  T.build = (contents)->
    previous = teact.resetStack null
    children = contents.apply teact, arguments
    teact.resetStack previous
    children
)

T.push connectDragSource(T.build ->
  T.div
  T.div
)

and I do believe that these two primitives are worthwhile considering to be included in the lib itself.

leiyangyou avatar Jan 12 '17 02:01 leiyangyou

Thanks for writing this up @leiyangyou! I can see how those primitives would be useful. I'd wait for a little more demand before expanding the interface. You could publish your code as a separate mixin (similar to https://github.com/goodeggs/teacup-camel-to-kebab) and we'll revisit based on traction?

hurrymaplelad avatar Jan 15 '17 21:01 hurrymaplelad