Make WordPress Core

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's profile nikeo Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.7
Component: Customize Keywords: has-patch
Focuses: javascript Cc:


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)

38947.patch (4.0 KB) - added by nikeo 7 years ago.
38947.2.patch (3.5 KB) - added by nikeo 7 years ago.
better indentation with tabs

Download all attachments as: .zip

Change History (10)

#1 @celloexpressions
7 years ago

  • Keywords needs-patch added

Can you make a patch for this @nikeo?

#2 @nikeo
7 years ago

@celloexpressions sure. I'll post something in the coming days.

7 years ago

#3 @nikeo
7 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 callbacks
  • unbindAll 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.

Last edited 7 years ago by nikeo (previous) (diff)

#4 @westonruter
7 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.

7 years ago

better indentation with tabs

#5 @nikeo
7 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!

#6 @westonruter
7 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.

#7 @nikeo
7 years ago

@westonruter sure :) of course, 100% understand.
I'll be pleased to help, it's an honour !

#8 @dlh
5 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to Future Release

Patch still applies, but we seem to still be in need of a use case, per comment:6.

Note: See TracTickets for help on using tickets.