• This repository has been archived on 12/Mar/2021
  • Stars
    star
    517
  • Rank 85,558 (Top 2 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Vue.js app demonstarting various use cases for the new composition API

Demo App for the Composition API

Context

THIS DEMO IS QUITE OLD AND OUTDATED - THE FINAL APIS in Vue 3.0 are different in a few places. This demo will not be updated.

This repository contains a demo application meant to demonstrate various usecases and patterns that arise with the new composition API that Vuejs 3 will introduce.

It is meant as an extension of a talk about the new API which I gave at Vuejs London 2019 on October 4th, 2019. You can find the slides here.

This repo represents the current state of my endeavor at playing with this API and seeing where it takes me, what patterns I can come up with etc., and I plan on adding new examples as I come up with / across them.

So keep in mind, it doesn't do anything useful, and it's also not a pretty thing to look at in the browser - it's meant as a demo of the API, nothing more. It's also not a good idea to take any of the demos as prescriptive in terms of the patterns used there. We as a community will have to figure out what the best patterns, the do's and don'ts will be, and I don't claim to have found the best ones yet.

The talk

The slides for the talk can be found here:

https://github.com/LinusBorg/talks/tree/master/2019-10-04%20Vuejs%20London

If/when a video recoding of the talk has ben published I will update the README with a link.

The code in /src does differ from the slide examples, as the had to be simplified to fit on slides and be explainable in a 30 min talk.

The code for the slide examples can be found in /slides-examples.

The examples - a quick overview

The routes (/views)

The /views folder contains route components, each containing examples for different use cases. Most of these examples make use of a few different composition functions.

  • Form.vue: Using a composition function to do reactive form validation
  • Images.vue: Build an Infinite Scrolling image gallery out of a few different composition functions (uses jsonplaceholder.typicode.com for the API - thanks!)
  • Posts.vue: With a slight variation of the code used in Images.vue, this component paginates a pre-populated array of posts.
  • Upload.vue: Demonstrates how to use composition functions to share a component's behaviour without a template, providing a more convenient and complete replacement of the "renderless components" pattern.

The composition functions (/composables)

The /composables folder contains all of the composition functions used in these example components. They cover quite some different use cases and often, build upon each other by composing other, more primitive compositions functions to achieve something new.

Not all of the functions already have an example in /views, but most do. A few are not finished yet, but hopefully soon will be.

Pagination

use-pagination.js

Provides reactive pagination state and functions to manipulate it.

use-array-pagination.js

Wrapping usePagination, it paginates an array that you pass to it.

Event handling

use-event.js

A very basic wrapper around the pattern of adding event listeners imperatively in mounted and removing them in beforeDestroy.

It's the basis for a couple of more advanced a examples wrapping it.

use-scroll.js

Reactive state tracking the window's scroll position (and any other element).

use-end-of-page.js

Extending use-scroll, this composition function accepts a callback that is run when the page has been scrolled to the bottom (margin can be specified).

use-media.js

Boolean Ref indicating whether the specified media query is fulfilled or not.

Handling Promises

use-promise.js

Wraps a function that returns a promise. Creates reactive state tracking loading state, error and result of the promise returned by calling that wrapped function.

use-endpoint.js

unfinished Similar to use-promise. Intended as an example of how to wrap a fetch library and cancel requests when the function is called again.

Current implementation isn't doing that in the way I want it to. Not used in any example right now for this reason.

Form Validation

use-validation.js

Reactive form validation, overly simplified.

"Renderless" component - File Dropzone

use-filednd.js

Returns various state and functions that can be used to easily build your own version of a dropzone for files.

use-global-dnd.js

Allows to track files being dragged into the browser window. Useful to highlight your dropzone when a file being dragged into the window so the user is guided to where the file can be dropped.

Store

This example is found in /src/store

Demonstrates how to create a Vuex-like state module and share it with components in a tree through provide & inject.

Still missing an example implementation

Vuejs 2 Plugin

This App uses the @vue/composition-api package, which makes this new API available for experimentation in Vue 2 (with a few caveats).

Contributing

I'd like to extend this project over time and collect more examples. I'll try and come up with a proper contributing guide later. Until then:

Examples

I'm open to contributions and happy to help. Just open an issue with a short description of the example you want to add and I'll quickly review it - then you can send a PR.

Tests

This repo has no tests so far, as I was short on time for my talk and don't work in a TDD fashion.

But I think adding tests would be great for example purposes, so I'm grateful for any contribution that adds tests for any of the examples.

More Repositories

1

portal-vue

A feature-rich Portal Plugin for Vue 3, for rendering DOM outside of a component, anywhere in your app or the entire document. (Vue 2 version: v2.portal-vue.linusb.org)
Vue
3,772
star
2

vue-mixable

Turn Vue Mixins into Composables with a simple wrapper function
TypeScript
282
star
3

vue-simple-portal

A simpler Portal implementation focussed on moving slot content to the end of the body element
JavaScript
217
star
4

vue-reactive-provide

Plugin/Mixin wrapping Vue's static 'provide/inject' feature allowing to easily pass reactive data to children
JavaScript
116
star
5

vue-lib-template

a personal template to boostrap the boilerplate for developing Vue libraries in a pnpm monorepo
TypeScript
70
star
6

vue-cli-plugin-test-attrs

A small plugin vor vue-cli 3 that adds a compiler plugin to remove data-test attributes when desired
JavaScript
65
star
7

slidev-theme-vuetiful

A Slidev Theme for my talks about Vue.js
Vue
63
star
8

talks

Collection of talks I gave
HTML
44
star
9

varia

Vuejs 3 baseline components and composables fo building WAI-ARIA compatible UI components
TypeScript
33
star
10

vueday-enterjs-vue3

Talk slides for Enter.js Vue Day (15.06.2021)
Vue
24
star
11

vue-filedrop

[WIP, NOT READY] A set of composable Vue components to create rich Dropzone-like UI elments and behaviour
JavaScript
14
star
12

talks_2018-11_VuejsRoadtrip-Berlin

Slides of the talk I gave at Vuejs Roadtrip Berlin, 2018-11-23
11
star
13

vue-directive-clickout

a directive to catch clicks outside of an element, compatible with Vue 2.0 only
10
star
14

vue-ko-fi-button

the Ko-fi Buttton (www.ko-fi.com) implemented as a Vue component (no affiliation)
Vue
6
star
15

vue-teleport-plus

A superior Teleport component experience for Vue 3
TypeScript
5
star
16

tailwindui-listbox-vue3-demo

TypeScript
5
star
17

eslint-config

JavaScript
4
star
18

create-vue-ts-eslint-airbnb-example

Example Repo demonstrating how to add the Airbnb config to a Typescript-Vue Project created with create-vue
Vue
4
star
19

demo-project-building-portals-in-vue

Created with CodeSandbox
Vue
3
star
20

vue-inject-helpers

[WIP] Wrapper components for Vue.js to pass injected properties as props to a child component
JavaScript
3
star
21

talk-thinking-in-script-setup

My talk for Vuejs Germany 2022 in Berlin
Vue
1
star
22

talk-cross-compatible-vue-components

Slides for my talk at Vuejs Amsterdam 2022
Vue
1
star