wsick / Fayde

Inspired by Silverlight; XAML engine using Javascript and rendering to the HTML5 Canvas.
MIT License
189 stars 27 forks source link

Subclass application #237

Closed opcodewriter closed 8 years ago

opcodewriter commented 8 years ago

Is it possible to subclass Application?

Code behind:

class App extends Fayde.Application {

    constructor() {
        super();
        this.RootVisual = new MainView();
    }
}

export = App;

XAML:

<myApp:App
        xmlns="http://schemas.wsick.com/fayde"
        xmlns:x="http://schemas.wsick.com/fayde/x"
        xmlns:vms="ViewModels"
        xmlns:controls="lib://fayde.controls"
        ThemeName="Metro">
    <Application.Resources>
    </Application.Resources>
``

I don't know which 'myApp' namespace to use
BSick7 commented 8 years ago

It's possible, but I don't recommend it. While it was typical to do this in WPF/Silverlight, there are better alternatives.

opcodewriter commented 8 years ago

how is it possible? why is it bad and what are the better alternatives? Closing issue is fine but I'd appreciate some useful info since I bothered writing the issue. Thanks!

BSick7 commented 8 years ago

Sorry. I was clipping fast through triage.

Philosophic Difference: In WPF/Silverlight, Application serves are your main entry point to the binary. It serves as more than just the UI Application. This is quite different from the browser world where the main entry point is the html page that is loading. Fayde Application serves "only" as a manager (input manager, surface manager, theme manager, etc.) of your UI. Additionally, Fayde was not built not to support code-behind. This complicates developer workflows and introduces nasty dependency challenges in an async browser world.

Technical Challenge: The main technical issue at hand is properly loading "your" version of Application before the application can start. It complicates bootstrapping and usually delays initial visual display (due to latency, not computing power).

Alternatives: Most usage of custom Application is to set up a main broker for the application. Instead, create an AppViewModel that holds this code and inject into the main default.fap:

<App
        xmlns="http://schemas.wsick.com/fayde"
        xmlns:x="http://schemas.wsick.com/fayde/x"
        xmlns:vms="ViewModels"
        ThemeName="Metro">
  <Grid>
    <Grid.DataContext>
      <vms:AppViewModel />
    </Grid.DataContext>
...

Another alternative: Send a PR to fayde altering the bootstrap process to launch some other entrypoint that you desire.