Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): generator events #1695

Closed
wants to merge 1 commit into from

Conversation

chu121su12
Copy link
Collaborator

Add events after each of tokens and preflights are generated. This should help usecases like #1617.

I'm unsure what data should be passed to the event. As for now, tokens & preflights event gets what each of them would normally produce, except in a cloned set to prevent modification.

@netlify
Copy link

netlify bot commented Oct 8, 2022

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit cf8f023
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/63410f40b5f01300088bfc96
😎 Deploy Preview https://deploy-preview-1695--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@chu121su12 chu121su12 marked this pull request as ready for review October 8, 2022 05:57
@chu121su12 chu121su12 requested a review from antfu as a code owner October 8, 2022 05:57
@Dunqing
Copy link
Member

Dunqing commented Oct 8, 2022

Should this and tokens/preflight be passed to the event?

@Dunqing
Copy link
Member

Dunqing commented Oct 8, 2022

Also, I think the event names should have keywords like after or end? because these events emit after all the work is finished.

@chu121su12
Copy link
Collaborator Author

@Dunqing I was copying the config event, so pardon me for the naming. tokens event send out the tokens that are generated in the current generate cycle, so does the preflights.

Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you consider this an alternative to #1617 or a complement to it?

I don't have a strong opinion on this, but my concern is that this will increase the package size for a relatively rare use case. And honest I would prefer for rules to keep as pure as possible and not rely on the event system. (e.g. the config hook is for up-level integrations but is not designed to be access directly in rules)

@@ -46,3 +46,81 @@ describe('generate-async', () => {
expect(order).eql([1, 2])
})
})

describe('firing-events', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a separate events.test.ts for this.

const order: number[] = []
const uno = createGenerator()

uno.events.on('config', () => order.push(order.length))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very sure what order.length is used for, maybe we could just use a fixed number?

@zyyv
Copy link
Member

zyyv commented Oct 8, 2022

If the event system is too heavy, what about using lifecycles in the config?

@chu121su12
Copy link
Collaborator Author

...this will increase the package size for a relatively rare use case. And honest I would prefer for rules to keep as pure as possible and not rely on the event system...
I didn't realize the x.event is only used for specific integration. And if that's the case, I'd choose not to pursue this addition; Except there's more reason otherwise

@chu121su12 chu121su12 closed this Oct 9, 2022
@chu121su12 chu121su12 deleted the feat/generator-events branch October 10, 2022 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants