awinogradov / react-xjst

DEPRECATED: use https://github.com/awinogradov/ddsl-react
3 stars 3 forks source link

should add at least one react element for single text node #2

Closed Guria closed 8 years ago

Guria commented 8 years ago
var react = require('react')
var reactXjst = require('react-xjst')
var vidom = require('bem-xjst').vidom

var templates = vidom.compile(function(){
  block('a')(
    tag()(false),
    content()('b')
  )
})

var bemreact = reactXjst(templates, react)

templates.apply({ block: 'a' }) // 'b'
bemreact({ block: 'a' })
TypeError: args.filter is not a function
    at makeComponent (./node_modules/react-xjst/lib/index.js:14:22)
    at ./node_modules/react-xjst/lib/index.js:34:19

Expected to be <span>b</span> with react@0.14 or plain text node with react@15.0

awinogradov commented 8 years ago

@Guria it's issue for https://github.com/bem/bem-xjst/pull/235

Guria commented 8 years ago

@awinogradov not really sure. xjst vidom engine doesn't fail. it returns string. moreover I can't see a way how it can be expressed as valid array of arguments. I suppose the way to handle string values depends on view package used. :( Correct me if I wrong.

Guria commented 8 years ago

Hmm. Seems React needs at least one root node. Nothing to fix with xjst engine, it works as intended.

var react = require('react')
var reactXjst = require('react-xjst')
var vidom = require('bem-xjst').vidom

var templates = vidom.compile(function(){
  block('a')(
    tag()(false),
    content()('b')
  )
})

var bemreact = reactXjst(templates, react)

templates.apply({ block: 'b', content: [{ block: 'a' }, ' text node'] })
// [ 'div', { className: 'b' }, 'b text node' ]
require('react-dom').renderToStaticMarkup(bemreact({ block: 'b', content: [{ block: 'a' }, ' text node'] }))
 // '<div class="b">b text node</div>'
Guria commented 8 years ago

The only issue here is a single top level text node. We need to wrap it with span either here or in xjst package.

Guria commented 8 years ago

ok, thx. closing here :)