1 Star 0 Fork 1

老鼠见到猫 / func-js

forked from 苍石 / func-js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
readme.md 15.90 KB
一键复制 编辑 原始数据 按行查看 历史
苍石 提交于 2021-01-13 13:05 . version 0.1.5

Classes

AsyncFuncInstanceFuncInstance
AsyncManager

This class used to initialize AsyncFuncInstance, register and listen event for async methods, manager caches and more storage info

Constants

managerDefaultOptions : Object

AsyncManager default options

defaultOptionsObject

get AsyncFuncInstance default options

eventOptions : Object

Initialed event's default options

PROCESS_START : string

The event name called on process start

PROCESS_END : string

The event name called on process end

METHOD_START : string

The event name called on method start

METHOD_END : string

The event name called on method end

AsyncFuncInstance ⇐ FuncInstance

Kind: global class
Extends: FuncInstance
Properties

Name Type Description
asyncManager AsyncManager The asyncManger instance bind to this instance

asyncFuncInstance.setManager(manager) ⇒ AsyncFuncInstance

Set the manager instance, it's helpful to using the methods without asyncManager param

Kind: instance method of AsyncFuncInstance
Returns: AsyncFuncInstance - This function instance

Param Type Description
manager AsyncManager The async manager instance

asyncFuncInstance.sign(local, [options]) ⇒ FuncInstance | function

Sign the async method with identity, to prevent the earlier results override the latest results in to async methods

Kind: instance method of AsyncFuncInstance
Returns: FuncInstance | function - This function instance

Param Type Description
local string This string is using to mark where the method called, two async methods with the same local will leads only one results
[options] Object The options for sign method
[options.identity] function A method to generate identity string while calling, default using utils.genID method
[options.asyncManager] AsyncManager Specified the async manager instance, default to using the params of setManager called

asyncFuncInstance.process([options], [asyncManager]) ⇒ FuncInstance | function

This method can hook target method's start, end callback, and registered to async manager. While result method called, METHOD_START, PROCESS_START and more event could be called in its async manager instance

Kind: instance method of AsyncFuncInstance
Returns: FuncInstance | function - This function instance

Param Type Description
[options] Object The options for process method
[options.start] function Before the target method called, the start method will be called without any params
[options.end] function After the target method called, the start method will be called without any params
[options.context] function The context for above methods
[asyncManager] AsyncManager Specified the async manager instance, default to using the params of setManager called

asyncFuncInstance.cache([options], [asyncManager]) ⇒ FuncInstance | function

Using this method to cache async function's return value

Kind: instance method of AsyncFuncInstance
Returns: FuncInstance | function - This function instance
See

Param Type Description
[options] Object The options for cache method
[options.type] CacheType Specified the cache type to using with cache
[options.setter] function If cache type set custom, this method will be called to set cache
[options.getter] function If cache type set custom, this method will be called to get cache
[options.keyPrefix] string The cache key's prefix
[options.expire] number Specified the expiration(ms) for the cache, default to be 5min
[asyncManager] AsyncManager Specified the async manager instance, default to using the params of setManager called

asyncFuncInstance.pre([args], [options], [asyncManager])

Pre called this method and cache it's returning results for next calling.

Kind: instance method of AsyncFuncInstance

Param Type Description
[args] Array.<*> The args as called params for method, and it will be identity for next calling.
[options] Object The options for pre method
[options.timeout] number Specified the timeout(ms) for this pre cache.
[options.once] boolean If set true, this pre cache will be removed once read it.
[options.context] * The context for target async method called.
[asyncManager] AsyncManager Specified the async manager instance, default to using the params of setManager called

asyncFuncInstance.preCache([asyncManager]) ⇒ FuncInstance | function

Get the method to catch the pre loaded cache

Kind: instance method of AsyncFuncInstance
Returns: FuncInstance | function - This function instance

Param Type Description
[asyncManager] AsyncManager Specified the async manager instance, default to using the params of setManager called

asyncFuncInstance.multiplyMerge([asyncManager]) ⇒ FuncInstance | function

If method execute asynchronously, multi methods with same params will execute many times. This method will prevent above, during the first method not finish, all method with the same params and using the method will not execute, and when the first method finished, the return value will be all waited methods' return value

Kind: instance method of AsyncFuncInstance
Returns: FuncInstance | function - This function instance

Param Type Description
[asyncManager] AsyncManager Specified the async manager instance, default to using the params of setManager called

AsyncManager

This class used to initialize AsyncFuncInstance, register and listen event for async methods, manager caches and more storage info

Kind: global class
Properties

Name Type Description
options Object Options of AsyncManager
memoryStorage Object Used to store cache in memories
eventsMapper Object Used to store events' mapper
signMapper Object Used to store the sign identity mapper

new exports.AsyncManager([options])

Param Type Description
[options] Object options to initialize manager

asyncManager.emit(eventName, [options])

Emit event

Kind: instance method of AsyncManager

Param Type Description
eventName string The event name to emit
[options] Object Options for emit method
[options.identity] Object Something to identity the event, only when event name with the same identity emit, the event callback will be fired
[options.params] Object Specified the params pass to event, ordering to send with event callback

asyncManager.on(eventName, callback, [options]) ⇒ string

Register event handler

Kind: instance method of AsyncManager
Returns: string - The event identity, you can using off method to cancel this event listener

Param Type Description
eventName string Event name for this handler callback
callback function While event emitting, this callback will be called
[options] Object Options for on method
[options.identity] Object Something to identity the event, only when event name with the same identity emit, the event callback will be fired
[options.params] Object Specified the params pass to event, ordering to send with event callback
[options.isOnce] Boolean If set true, the callback will only triggered once, default false
[options.isAsync] Boolean If set true, the callback will exec async

asyncManager.off(eventIdentity)

Remove the event register

Kind: instance method of AsyncManager

Param Type Description
eventIdentity string | Boolean The return value of on method to cancel listening, if set true, all event will be canceled.

asyncManager.getMemoryStorage() ⇒ Object

Get storage cached in memory

Kind: instance method of AsyncManager

asyncManager.getExistedSignMapper() ⇒ Object

Get signed mapper existed

Kind: instance method of AsyncManager

asyncManager.use(func, [options]) ⇒ AsyncFuncInstance | function

Initialize AsyncFuncInstance using options and using this AsyncManager instance

Kind: instance method of AsyncManager
Returns: AsyncFuncInstance | function - The AsyncFuncInstance instance

Param Type Description
func function Specified the target function to be AsyncFuncInstance instance
[options] Object The options to initialize AsyncFuncInstance

asyncManager.getPreCacheStorage(instanceId) ⇒ Object

Get the pre cache of target instance

Kind: instance method of AsyncManager

Param Type Description
instanceId string The id of target instance

AsyncManager.use(func, [options]) ⇒ AsyncFuncInstance | function

Initialize AsyncFuncInstance using options and new AsyncManager instance

Kind: static method of AsyncManager
Returns: AsyncFuncInstance | function - The AsyncFuncInstance instance

Param Type Description
func function Specified the target function to be AsyncFuncInstance instance
[options] Object The options to initialize AsyncFuncInstance

CacheType : enum

Enum for cache-type values.

Kind: global enum
Read only: true
Properties

Name
LOCAL_STORAGE
SESSION_STORAGE
MEMORY
CUSTOM

managerDefaultOptions : Object

AsyncManager default options

Kind: global constant
Read only: true

defaultOptions ⇒ Object

get AsyncFuncInstance default options

Kind: global constant

eventOptions : Object

Initialed event's default options

Kind: global constant
Read only: true

PROCESS_START : string

The event name called on process start

Kind: global constant

PROCESS_END : string

The event name called on process end

Kind: global constant

METHOD_START : string

The event name called on method start

Kind: global constant

METHOD_END : string

The event name called on method end

Kind: global constant

JavaScript
1
https://gitee.com/tigger-home/func-js.git
git@gitee.com:tigger-home/func-js.git
tigger-home
func-js
func-js
master

搜索帮助