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

Pico not mounting #4

Closed
patrickbjohnson opened this issue Jun 3, 2019 · 1 comment
Closed

Pico not mounting #4

patrickbjohnson opened this issue Jun 3, 2019 · 1 comment

Comments

@patrickbjohnson
Copy link

Attempting to use Pico as the script/module manager for a WP site.
But for some reason when adding a basic component into picoapp it's not executing the script.

Can confirm scripts are being loaded correctly and exist within all code contents which are being compiled via webpack.

Main JS

import { picoapp } from 'picoapp'
import slider from './slider'

const app = picoapp({ slider })
app.mount()

Component JS

import { component } from 'picoapp'
export default component((node, ctx) => {
  console.log(node, 'mounted on slider')

  return (node) => {
    console.log('ran foo!')
  }
})

Slider Twig File

<section class="billboard-block"  data-component="slider">
 Test Slider Content
</section>

@patrickbjohnson
Copy link
Author

SOLUTION BELOW
Realized the script was being added in the head of the document, thus running and parsing before the DOM completely loaded.

SOLUTION

import { picoapp } from 'picoapp'
import slider from './slider'

const app = picoapp({ slider })

window.addEventListener('DOMContentLoaded', (event) => {
  app.mount()
})

Note, wrapped the mount method in DOMContentLoaded

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

1 participant