最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is state management in jQuery? - Stack Overflow

programmeradmin1浏览0评论

In jQuery UI Widget Factory:

The jQuery UI Widget Factory is an extensible base on which all of jQuery UI's widgets are built. Using the widget factory to build a plugin provides conveniences for state management, as well as conventions for mon tasks like exposing plugin methods and changing options after instantiation.

Could someone please explain in simple words (preferably with an example ), what does state management mean in this context? The state management I know is browser history state management (maybe using HTML5 History API, or history.js) but I don't see any relationship between it and jQuery UI Widget Factory purposes.

Your help is appreciated.

In jQuery UI Widget Factory:

The jQuery UI Widget Factory is an extensible base on which all of jQuery UI's widgets are built. Using the widget factory to build a plugin provides conveniences for state management, as well as conventions for mon tasks like exposing plugin methods and changing options after instantiation.

Could someone please explain in simple words (preferably with an example ), what does state management mean in this context? The state management I know is browser history state management (maybe using HTML5 History API, or history.js) but I don't see any relationship between it and jQuery UI Widget Factory purposes.

Your help is appreciated.

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Apr 4, 2015 at 12:01 Adib ArouiAdib Aroui 5,0656 gold badges44 silver badges95 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 3

From "Why Use the Widget Factory?" section of documentations:

Stateless vs. Stateful Plugins

Most jQuery plugins are stateless; they perform some action and their job is done. For example, if you set the text of an element using .text( "hello" ), there is no setup phase and the result is always the same. For these types of plugins, it makes sense to just extend jQuery's prototype.

However, some plugins are stateful; they have full life cycles, maintain state, and react to changes. These plugins require a lot of code dedicated to initialization and state management (and sometimes destruction). This results in a lot of boilerplate for building stateful plugins. Even worse, each plugin author may manage life cycles and state differently, resulting in different API styles for different plugins. The widget factory aims to solve both problems, removing the boilerplate and creating a consistent API across plugins.

发布评论

评论列表(0)

  1. 暂无评论