Opened 8 years ago
Last modified 5 years ago
#38947 new enhancement
Proposition to add an optimized api.Events manager to the api.Value constructor
Reported by: | nikeo | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Customize | Keywords: | has-patch |
Focuses: | javascript | Cc: |
Description
It would be convenient to be able to bind, unbind and trigger api.Value
instances by event id, instead of using only functions param like it's the case now.
The api.Values
constructor is already extended with the api.Events
manager object, which is very useful. I propose to do something similar with the api.Value
constructor.
In order to not overload the api.Value.topics
object with anonymous functions, a possible optimization would be to fallback on the previous binding method of api.Value
, with a function type param directly added to the api.Value.callbacks
( $.Callbacks
) object, if no id is provided for the callback, and to populate the api.Value.topics
property only when an id has been provided on binding.
Attachments (2)
Change History (10)
#3
@
8 years ago
Two methods have been added to the api.Value constructor
trigger
which triggers the bound callbacks of a specific topic, or trigger the anonymous callbacksunbindAll
which unbinds all previously bound functions of a callbacks topic if specified or unbinds all functions if no topic is specified
The set
, bind
and unbind
methods have been adapted to the new event manager.
I've also proposed a new optional argument object to the set
method that was not initially scoped in the proposition. The proposed argument allows us to "silently" set an api.Value()
instance, whithout firing the callbacks.
This code ensures a backward compatibility with the current API, since it allows to bind an api.Value
both ways : with or without a topic id.
#4
@
8 years ago
@nikeo it's hard to read the diff since it looks like you're using spaces but core uses tabs. Could you refresh?
Also, similar to #33428 I'd like to know what the core use case would be for this. How would core be improved with this change? If not, then perhaps it should remain plugin territory. You can have a plugin that extends/wraps wp.customize.Value.prototype
with the new methods and modified methods to start feedback from plugin developers.
#5
@
8 years ago
@westonruter patch updated.
This enhancement is not meant to solve a core problem, but to provide more flexibility for developers when working with the api.
But now I understand that you're currently looking for enhancements that have a direct core impact. OK got it!
Cheers
#6
@
8 years ago
@nikeo you've got good ideas! It's just without there being a direct user experience improvement, technical defect fix, or alignment the customization goals for 2017 it is difficult to prioritize. If you can find an area of core where this would directly improve things it would be easier to get traction.
Can you make a patch for this @nikeo?