0.1.0 β€’ Published 5 years ago

uppy-vuex v0.1.0

Weekly downloads
2
License
ISC
Repository
-
Last release
5 years ago

Uppy-Vuex alpha

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.

Caution: Some method signatures are slightly different, so read carefully! (The changed methods are marked with ❗️)

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

Getters

UsageEffectDoc 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 instanceNone (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

UsageEffectNotesDoc link
dispatch("uppy/init", uppyOptions)Initialize the underlying Uppy instanceuppyOptions 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.

UsageEffectDoc 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

UsageEffectNotesDoc 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

UsageEffectNotesDoc 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.

UsageEffectNotesDoc 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.

UsageEffectNotesDoc 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.

UsageEffectNotesDoc 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.