Giter Site home page Giter Site logo

uppyvuex's Introduction

Uppy-Vuex [alpha]

npm version mit license

A lightweight Vuex wrapper around the Uppy file upload library.

Installation

npm install uppy-vuex

Import & Initialization

import Vuex from 'vuex';
import UppyVuex from "uppy-vuex";


// Add UppyVuex as a Vuex module
// (for hot installation with code-splitting, see Appendix)
const store = new Vuex.Store({
    modules: {
        uppy: UppyVuex
    }
})

// Initialize Uppy
store.dispatch("uppy/init");

// You can now use uppy from anywhere in your app!

You'll need to install one of Uppy's uploader plugins before Uppy can do any useful uploading. See their excellent getting started docs.

Usage

Uppy-Vuex exposes the complete Uppy Core API. All methods are available by dispatching uppy/<uppy method>, or by calling the uppy/<getter> getters.

Note: Uppy-Vuex is a namespaced module. This means that all getters and actions must be prefaced with uppy/

Getters

Usage Effect Doc link
getters["uppy/isReady"] Has the underlying Uppy instance been initialized yet? (If false, dispatch uppy/init) None (Uppy-Vuex only)
getters["uppy/getUppyInstance"] Access the underlying Uppy instance None (Uppy-Vuex only)
getters["uppy/getFile"](fileID) Get a specific file object by its ID. πŸ”— Docs
getters["uppy/getFiles"] Get an array of all file objects in Uppy.. πŸ”— Docs
getters["uppy/getID"] Get the Uppy instance ID πŸ”— Docs
getters["uppy/getPlugin"](pluginID) Get a plugin by its id to access its methods. πŸ”— Docs
getters["uppy/getState"] Returns the current state from the Store. πŸ”— Docs

Actions

All Uppy active methods are actions, and not mutations for the sake of simplicity. Uppy-Vuex does not define any mutations. All actions return the result of the underlying Uppy method.

Basic

Usage Effect Notes Doc link
dispatch("uppy/init", uppyOptions) Initialize the underlying Uppy instance uppyOptions is what would be passed to the Uppy() constructor. πŸ”— Docs
dispatch("uppy/addFile", fileObject) Add a new file to Uppy’s internal state. πŸ”— Docs
dispatch("uppy/removeFile", fileID) Remove a file from Uppy. πŸ”— Docs
dispatch("uppy/upload") Start uploading selected files. Return a Promise that yields a results object {successful: [], failed: []} πŸ”— Docs

Pause / Resume

These will only work if the upload plugin supports resumable uploads, such as Tus.

Usage Effect Doc link
dispatch("uppy/pauseResume", fileID) Toggle pause/resume on an upload. πŸ”— Docs
dispatch("uppy/pauseAll") Pause all uploads. πŸ”— Docs
dispatch("uppy/resumeAll") Resumes all uploads. πŸ”— Docs

Retry

Usage Effect Doc link
dispatch("uppy/retryUpload", fileID) Retry an upload (after an error, for example). πŸ”— Docs
dispatch("uppy/retryAll") Retry all uploads (after an error, for example). πŸ”— Docs

Cancellation and Teardown

Usage Effect Notes Doc link
dispatch("uppy/cancelAll") Cancel all uploads, reset progress and remove all files. πŸ”— Docs
dispatch("uppy/reset") Stop all uploads in progress and clear file selection, set progress to 0. Restores Uppy to pristine pre-interaction state. πŸ”— Docs
dispatch("uppy/close") Uninstall all plugins and close down this Uppy instance. Also runs uppy/reset before uninstalling. All subsequent actions will fail unless uppy/init is dispatched again πŸ”— Docs

Advanced

❗️Some of these actions have modified method signatures.

Usage Effect Notes Doc link
dispatch("uppy/setFileMeta", {fileID, data}) Update metadata for a specific file. πŸ”— Docs
dispatch("uppy/setMeta", data) Alters global meta object in state, the one that can be set in Uppy options and gets merged with all newly added files.. πŸ”— Docs
dispatch("uppy/ setFileState", {fileID, fileState}) Update the state for a single file. πŸ”— Docs
dispatch("uppy/ setState", patch) Update Uppy’s internal state (See docs). See also: the getState getter πŸ”— Docs

Plugins

❗️These actions have modified method signatures.

Usage Effect Notes Doc link
dispatch("uppy/use", {plugin, options}) Add a plugin to Uppy, with an optional plugin options object. πŸ”— Docs
dispatch("uppy/removePlugin", instance) Uninstall and remove a plugin. See also: the getPlugin getter πŸ”— Docs

Registering for Events

❗️These actions have modified method signatures.

Usage Effect Notes Doc link
dispatch("uppy/on", {event, callback}) Subscribe to an uppy-event. See the full list of events πŸ”— Docs
dispatch("uppy/off", {event, callback}) Unsubscribe to an uppy-event. See the full list of events πŸ”— Docs

Uppy Logging

❗️These actions have modified method signatures.

Usage Effect Notes Doc link
dispatch("uppy/log", {message, type}) Logs to the console, only if uppy.opts.debug is set to true. ❗️Silent in production πŸ”— Docs
dispatch("uppy/info", {message, type, duration}) Sets a message in state, with optional details, that can be shown by notification UI plugins. πŸ”— Docs

Limitations

  • UppyVuex can only contain a single Uppy instance at a time. If you need to have multiple seperate uploaders on a page, the UppyVuex will not meet your needs.

Bugs

UppyVuex contains practically no logic, so you're probably best off trying to repro your issues on Uppy itself. Issues can be filed against this repo.

Contributing

The current maintainer is AnalyzePlatypus.

License

This project is open-source under the MIT license.

uppyvuex's People

Contributors

analyzeplatypus avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

geo-connor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.