Edit this page

up.Preview up.Preview.prototype.run(nameOrFn, options)
Instance method

This feature is experimental. Please share your experiences so we know what to keep or change.

Runs another preview function.

Example

To run another preview function registered with up.preview(), pass it's name:

up.preview('foo', function(preview) { // mark-phrase "'foo'"
  // ...
})

up.preview('bar', function(preview) {
  preview.run('foo') // mark-phrase "'foo'"
})

Undo callbacks are merged

All undo callbacks from the other preview will be added to this preview.

In the example below, preview2 will call both undo1() and undo2() when the preview ends:

function undo1() { ... }
function undo2() { ... }

up.preview('preview1', function(preview) {
  preview.undo(undo1)
})

up.preview('preview2', function(preview) {
  preview.run('preview1')
  preview.undo(undo2)
})

Passing options

To call a preview with parameters, pass an options object as a second argument:

up.preview('foo', function(preview, { size, speed }) {
  // ...
})

up.preview('bar', function(preview) {
  preview.run('foo', { size: 'large', speed: 'fast' })
})

Sharing behavior between previews

Instead of running a preview by its registered name, you can pass any function that accepts an up.Preview argument.

This is a way to share common behavior between multiple preview functions:

function shared(preview) {
  // ...
}

up.preview('foo', function(preview) {
  preview.run(shared)
})

up.preview('bar', function(preview) {
  preview.run(shared)
})

Parameters

nameOrFn string|Function(up.Preview, Object)

Another preview function or its registered name.

options Object

Parameters that will be passed to the other preview function.