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

Easier to use API #13

Open
darsain opened this issue Oct 26, 2016 · 0 comments
Open

Easier to use API #13

darsain opened this issue Oct 26, 2016 · 0 comments

Comments

@darsain
Copy link

darsain commented Oct 26, 2016

Currently we have to do a lot of boilerplate:

let windowState = windowStateKeeper({
  defaultWidth: 1000,
  defaultHeight: 800
});

win = new BrowserWindow({
  x: windowState.x,
  y: windowState.y,
  width: windowState.width,
  height: windowState.height,
  // ... other props
});

Why not just make the returned state object support object assignment so it can seamlessly blend with the BrowserWindow options? Then we can just:

win = new BrowserWindow(Object.assign(windowProps, windowStateKeeper()));

In this API, you don't even need defaultWidth|defaultHeight options, since they can be defined in windowProps, and will be overridden by recalled state if present.

By support assignment I mean:

  • Construct the state object so its enumerable properties match BrowserWindow options.
  • Describe methods and other proprietary stuff as non-enumerable so they don't pollute the BrowserWindow options object.

This would be the proposal with no magic and the lowest API surface I can think of. If you want to keep your proprietary props and methods, and don't like the non-enumerable treatment, a different approach might be a method that does this:

win = new BrowserWindow(windowStateKeeper().assign(windowProps));

Or even better, an API that would also eliminate the need for #manage(win):

win = windowFromState(props); // BrowserWindow instance created by state keeper

props in here would be a combination of your options and BrowserWindow options. Your options would be consumed and deleted from this object, which would then be extended with recalled state, and passed to new BrowserWindow() on creation.

Just make sure to fire stuff like win.maximize() on next tick to give us time to bind listeners.

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

No branches or pull requests

1 participant