Allow users to lazy load on another package
This commit is contained in:
66
doc/dep.txt
66
doc/dep.txt
@ -15,6 +15,7 @@ Table of Contents *dep-table-of-contents*
|
||||
6. Examples |dep-examples|
|
||||
- Declaring Dependencies |dep-examples-declaring-dependencies|
|
||||
- Modules |dep-examples-modules|
|
||||
- Lazy Loading |dep-examples-lazy-loading|
|
||||
7. Credits & License |dep-credits|
|
||||
|
||||
==============================================================================
|
||||
@ -293,6 +294,27 @@ into the options table to re-run the binding after loading the package. You
|
||||
may choose to include your own logic by passing a function to the `rerun`
|
||||
field or disable the built-in logic by passing false.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
LOAD:PLUGIN *dep-lazy-loading-api-plugin*
|
||||
|
||||
`load:plugin` is a function which allows you to specify another plugin for the
|
||||
package to load after. It takes two arguments: `plugin` which is the name of
|
||||
the plugin you want to follow like: 'user/package'. The second argument is
|
||||
`opts` which is a table with one option: `callback` which is a function. The
|
||||
following is an example:
|
||||
>lua
|
||||
load:plugin("user/package", {})
|
||||
<
|
||||
Which is the same as:
|
||||
>lua
|
||||
load:plugin("user/package", {
|
||||
callback = function()
|
||||
self:cleanup()
|
||||
end
|
||||
})
|
||||
<
|
||||
When 'user/package' is already loaded the `callback` is called immediately.
|
||||
|
||||
LAZY LOADING API SHORTHANDS *dep-lazy-loading-api-shorthands*
|
||||
|
||||
On occasion you may wish to only define one condition for the package to load.
|
||||
@ -589,6 +611,50 @@ declared in that module.
|
||||
}
|
||||
}
|
||||
<
|
||||
LAZY LOADING *dep-examples-lazy-loading*
|
||||
|
||||
Lazy loading is a very complicated topic, and therefore this part of the
|
||||
documentation assumes you have experience with regular package managment.
|
||||
Let's go over loading order, and how the lazy loader determines what needs to
|
||||
be loaded.
|
||||
|
||||
Let's say we have the following spec:
|
||||
>lua
|
||||
{ "user/package",
|
||||
lazy = true,
|
||||
deps = "user/dependent"
|
||||
}
|
||||
<
|
||||
This is the same as the following:
|
||||
>lua
|
||||
{ "user/package",
|
||||
lazy = true
|
||||
},
|
||||
|
||||
{ "user/dependent",
|
||||
reqs = "user/package",
|
||||
lazy = require("dep.lazy.loader.short").plugin("user/package")
|
||||
}
|
||||
<
|
||||
What you're seeing is implicit lazy loading. By default dep will lazy load
|
||||
dependents who are explicitly defined in the spec. Now if we we're to modify
|
||||
'user/dependent' like so:
|
||||
>lua
|
||||
{ "user/package",
|
||||
lazy = true
|
||||
},
|
||||
|
||||
{ "user/dependent",
|
||||
reqs = "user/package",
|
||||
lazy = function(load)
|
||||
load:plugin("user/package")
|
||||
load:cmd("LoadDependent")
|
||||
end
|
||||
}
|
||||
<
|
||||
If we were to call the command `:LoadDependent` it would first load
|
||||
'user/package', and then load 'user/dependent'.
|
||||
|
||||
==============================================================================
|
||||
7. Credits & License *dep-credits*
|
||||
|
||||
|
Reference in New Issue
Block a user