Repository navigation
Add onPageAdded constructor option - #1871
Merged
Merged
Conversation
The pageAdded event is emitted inside addPage(), and the constructor adds the first page before a caller can attach a listener. A page added that way could not be written to with on('pageAdded'). The new onPageAdded option takes a function, registers it before the automatic first page is added, and calls it with the document for every page. A first page added by hand with autoFirstPage: false is covered too.
The emission point of pageAdded does not change. Listeners attached with on() or once() see the same events in the same order as before, and no event methods are overridden.
Fixes foliojs#1529
Agent: claude
Member
|
Much better. Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
A feature, closes #1529. Replaces closed #1870 by adding an
onPageAddedconstructor option. Issue #1529 has no maintainer confirmation that this proposal fixes the reported case.An
onconstructor option lets callers attach several listeners before the first page and keeps original listener references for removal. It adds a broader event-registration contract than existing focused options.An
onPageAddedoption handles the first-page case directly and fits existing single-purpose options. It runs synchronously with the document argument on every added page, includingautoFirstPage, in Node and browser builds. Because the constructor registers a wrapper, passing the original callback tooff()will not remove it.This PR picks
onPageAddedfor a small, consistent cross-runtime API while leaving existing callers unchanged. Switching to theonoption before merge is easy.Four of the new tests fail on master. The new tests pass on this branch.
Checklist: