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

In jQuery UI Widget Factory:The jQuery UI Widget Factory is an extensible base on which all ofjQuery U

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745269519a4619658.html

相关推荐

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

    In jQuery UI Widget Factory:The jQuery UI Widget Factory is an extensible base on which all ofjQuery U

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信