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

Remove global ags object #114

Merged
merged 8 commits into from
Oct 14, 2023
Merged

Remove global ags object #114

merged 8 commits into from
Oct 14, 2023

Conversation

Aylur
Copy link
Owner

@Aylur Aylur commented Oct 2, 2023

This is necessary for #107, beause the ags global object imported every service and as a side effect their dependent libraries had to be loaded.

Here is how to import everything

import Widget from 'resource:///com/github/Aylur/ags/widget.js'
import { Box, Button }  from 'resource:///com/github/Aylur/ags/widget.js'

import * as Utils from 'import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
import { execAsync, exec } from 'resource:///com/github/Aylur/ags/utils.js';

import App from 'resource:///com/github/Aylur/ags/app.js'
import Variable from 'resource:///com/github/Aylur/ags/variable.js'

// this is the base Service class that you want to subclass
// Service.Audio and other builtin services are no longer accessible like this
import Service from 'resource:///com/github/Aylur/ags/service.js'

// builtin services are at 'resource:///com/github/Aylur/ags/service/<lower-casename>.js'
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';

The wiki is already updated and longer mentions the ags object
Services are now the instances themselves and not a static wrapper class

// this is no longer valid
Audio.instance.connect();

// you should now do this instead
Audio.connect()

// if you have a callback like this
onClicked: Notificatitions.clear

// update it to
onClicked: () => Notificatitions.clear()

// or
onClicked: Notificatitions.clear.bind(Notifications)

Aylur and others added 8 commits October 2, 2023 17:14
I finally figured out what caused the prop setters not setting the private value correctly, it was because typescript needs the private props to be pre defined and this overwrote the value the gobject constructor set
I didn't find a way to tell typescript to not throw an error for this, so there are a bunch of @ts-expect-error

also started using Service.pspec on Widgets to save some lines, and added more prop definitions and notify calls
@Aylur Aylur merged commit 7512796 into main Oct 14, 2023
2 checks passed
@Aylur Aylur deleted the remove-global-ags-object branch January 28, 2024 00:11
This pull request was closed.
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.

1 participant