schultek / jaspr

Modern web framework for building websites in Dart. Supports SPAs, SSR and SSG.
https://jasprpad.schultek.de
MIT License
1.23k stars 76 forks source link

Dom events not working #170

Closed TangoRain closed 7 months ago

TangoRain commented 8 months ago

Hi mans, doom events is not worked, please, check this code

class InheritedCount extends InheritedComponent {
  InheritedCount(this.count, {required Component child}) : super(child: child);

  final int count;

  @override
  bool updateShouldNotify(covariant InheritedCount oldComponent) {
    return count != oldComponent.count;
  }
}

class App extends StatefulComponent {
  const App({Key? key}) : super(key: key);

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  int count = 0;

  @override
  Iterable<Component> build(BuildContext context) sync* {
    yield InheritedCount(
      count,
      child: CountLabel(),
    );

    yield DomComponent(
      tag: 'button',
      id: "sdf",
      events: {
        'click': (e) {
          print("sdfsdf");
          setState(() => count++);
        },
      },
      child: Text('Press Me'),
    );
  }
}

class CountLabel extends StatelessComponent {
  const CountLabel({Key? key}) : super(key: key);

  @override
  Iterable<Component> build(BuildContext context) sync* {
    var count =
        context.dependOnInheritedComponentOfExactType<InheritedCount>()!.count;
    yield Text('Count is $count');
  }
}

run jaspr serve and this
https://github.com/schultek/jaspr/assets/26673298/246a4e87-c99b-4f30-99ed-02529086cc67

meta: [✓] Jaspr CLI (Version 0.10.0) • Dart Version 3.2.0 (stable) (Tue Nov 14 18:26:59 2023 +0000) on "macos_arm64" at dart • Running on macos Version 14.1.1 (Build 23B81) - Locale ru-RU • Analytics: Enabled

[✓] Current Project • Dependencies on core packages: • jaspr: ^0.10.0 • jaspr_builder: ^0.10.0 (dev) • Uses server-side rendering: true • Uses experimental compilers: false • Uses flutter embedding: false

TangoRain commented 8 months ago

try : jaspr clean jaspr build (and start prod server) change browse

work on macos

TangoRain commented 8 months ago

try yield DomComponent( tag: 'button', id: "sdf", events: events(onClick: () { print("click"); }), child: Text('Press Me'), );

not working 
TangoRain commented 8 months ago

why, i'am think, is not working?

[SERVER] The Dart VM service is listening on http://127.0.0.1:8181/qksvtipkIrE=/ [SERVER] The Dart DevTools debugger and profiler is available at: http://127.0.0.1:8181/qksvtipkIrE=/devtools?uri=ws://127.0.0.1:8181/qksvtipkIrE=/ws [SERVER] [WARNING] Jaspr was not initialized. Call Jaspr.initializeApp() before calling runApp(). This will be required in a future version of jaspr and result in an error. [SERVER] [INFO] Server hot reload is enabled. [SERVER] [INFO] Running app in debug mode [SERVER] [INFO] Serving at http://localhost:8080

terminal not show message "click"

TangoRain commented 8 months ago

UPD

  await tester.click(find.tag('button').first); // it's worked 

  but, in browse not worked 
TangoRain commented 8 months ago

upd try to jaspr generate -> get this error [CLI] [ERROR] FailureType: 73

and get this html file

<!DOCTYPE html>
<p>Count is 0</p>
<button id="sdf">Press Me</button>
<button>sdfsdf</button>
TangoRain commented 8 months ago
Снимок экрана 2024-02-06 в 08 53 45

test.dart.js not found

schultek commented 8 months ago

Can you run jaspr serve --verbose and post the full log

TangoRain commented 8 months ago

hi, run command [CLI] Starting jaspr in development mode... [BUILDER] Connecting to the build daemon... [BUILDER] Generating build script... [BUILDER] Generating build script completed, took 163ms [BUILDER] Starting daemon... [BUILDER] Initializing inputs [BUILDER] Reading cached asset graph... [BUILDER] Reading cached asset graph completed, took 131ms [BUILDER] Checking for updates since last build... [BUILDER] Checking for updates since last build completed, took 451ms [BUILDER] Initializing inputs [BUILDER] Reading cached asset graph... [BUILDER] Reading cached asset graph completed, took 131ms [BUILDER] Checking for updates since last build... [BUILDER] Checking for updates since last build completed, took 451ms [BUILDER] Setting up file watchers... [BUILDER] Setting up file watchers completed, took 2ms [BUILDER] Registering build targets... [BUILDER] Starting initial build... [BUILDER] Starting resource servers... [CLI] Starting web builder... [BUILDER] About to build [web]... [BUILDER] Running build... [CLI] Building web assets... [BUILDER] Running build completed, took 72ms [BUILDER] Caching finalized dependency graph... [BUILDER] Caching finalized dependency graph completed, took 117ms [BUILDER] Succeeded after 193ms with 0 outputs (0 actions) [BUILDER] -------------------------------------------------------------------------------------------------------------------------------------------------------------------- [CLI] Done building web assets. [CLI] Starting server... [CLI] Server started. [SERVER] The Dart VM service is listening on http://127.0.0.1:8181/SoHxDBdATEk=/ [SERVER] The Dart DevTools debugger and profiler is available at: http://127.0.0.1:8181/SoHxDBdATEk=/devtools?uri=ws://127.0.0.1:8181/SoHxDBdATEk=/ws [SERVER] [WARNING] Jaspr was not initialized. Call Jaspr.initializeApp() before calling runApp(). This will be required in a future version of jaspr and result in an error. [SERVER] [INFO] Server hot reload is enabled. [SERVER] [INFO] Running app in debug mode [SERVER] [INFO] Serving at http://localhost:8080----- after click ----- nothing

schultek commented 8 months ago

Are you missing the @client annotation on the App component?

TangoRain commented 8 months ago

add annotation, but not working

schultek commented 8 months ago

Can you create a new project with the basic template and see where the setup is different.

TangoRain commented 8 months ago

окей, jaspr create ?

TangoRain commented 8 months ago
Снимок экрана 2024-02-09 в 02 57 15

--create app

Снимок экрана 2024-02-09 в 02 58 33

-- add button

Снимок экрана 2024-02-09 в 02 59 42

--run jaspr serve

Снимок экрана 2024-02-09 в 03 00 31

--button event not working

TangoRain commented 8 months ago

this new project project

schultek commented 8 months ago

this new project project

I downloaded this and it works fine.

schultek commented 8 months ago

Ahh wait: You need to check the browser console for client logs. The terminal process currently does not stream client logs.

TangoRain commented 7 months ago

okay, logs is working on browse in project 1 app. Now, can you view project two ? (with button and state changes) project two

TangoRain commented 7 months ago

mb, how to restart all jaspr framework ? mb delete all jaspr & jaspr_cli?

schultek commented 7 months ago

I recommend you join the discord server, you can ask questions to the community and there is also a code-review channel.