Skip to content

link rel=import with package: URLs doesn't propagate correctly to relative URLs in the  #11034

@DartBot

Description

@DartBot

This issue was originally filed by papi...@gmail.com


To reproduce
============
Create static_test web-ui project with following 3 files:

static_test/lib/singleton.dart


class Singleton {
  static final Singleton singleton = new Singleton.();

  factory Singleton() => _singleton;

  Singleton._() {
    print('Creating singleton with hash code: $hashCode');
  }

  String toString() => hashCode.toString();
}

static_test/lib/print_singleton.html


<!DOCTYPE html>
<html>
  <body>
    <element name="print-singleton" extends="div">
      <template>Singleton in web component: {{singleton}}</template>
      <script type="application/dart">
        import 'package:web_ui/web_ui.dart';
        import 'singleton.dart';

        class PrintSingleton extends WebComponent {
          Singleton singleton = new Singleton();

          void created() {
            print("Singleton's hash code in web component: $singleton");
          }
        }
      </script>
    </element>
  </body>
</html>

static_test/web/main.html


<!DOCTYPE html>
<html>
  <head>
    <link rel="import" href="package:singleton_test/print_singleton.html">
  </head>
  <body>
    <print-singleton></print-singleton>

    <script type="application/dart">
      import 'dart:html';
      import 'package:web_ui/web_ui.dart';
      import 'package:singleton_test/singleton.dart';

      void main() {
        Singleton singleton = new Singleton();
        print("Singleton's hash code in main function: $singleton");
      }
    </script>
  </body>
</html>

Output
======
The expected output is to see same hash code 4 times.

Instead when i run the project i see following output:


Creating singleton with hash code: 866268140
Singleton's hash code in main function: 866268140
Creating singleton with hash code: 489263892
Singleton's hash code in web component: 489263892

I am using
==========
Windows 8 Pro, 64 bit
Dart Editor version 0.5.11_r23200
Dart SDK version 0.5.11.1_r23200
Web UI version 0.4.8+4

Why doesn't the static variable have a same value in same isolate?

The singleton pattern in http://stackoverflow.com/questions/12649573/how-do-you-build-a-singleton-in-dart doesn't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-obsoleteClosed as the reported issue is no longer relevant

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions