DEV Community

Discussion on: What's the difference between a library and a framework?

Collapse
peerreynders profile image
peerreynders
<script type="module">
  import { createApp } from 'https://unpkg.com/petite-vue?module'

  function Counter(props) {
    return {
      count: props.initialCount,
      inc() {
        this.count++
      },
      mounted() {
        console.log(`I'm mounted!`)
      }
    }
  }

  createApp({
    Counter
  }).mount()
</script>
Enter fullscreen mode Exit fullscreen mode

This starts it effectively making it the "main program"

  createApp({
    Counter
  }).mount()
Enter fullscreen mode Exit fullscreen mode

This is user code that is called by it

  function Counter(props) {
    return {
      count: props.initialCount,
      inc() {
        this.count++
      },
      mounted() {
        console.log(`I'm mounted!`)
      }
    }
  }
Enter fullscreen mode Exit fullscreen mode
  • If your code calls it, it's a library.
  • If it calls your code, it's a framework.

therefore it (petite-vue) is a framework.