Git Product home page Git Product logo

Comments (3)

BillDStrong avatar BillDStrong commented on May 28, 2024

I too dislike the implementation. So I asked myself, how would I want to use this.

Essentially, I would like to create a package that contained library that when imported, would do the right thing depending on my environment.

So, how about this.

main.dart

import library.dart;

 // F3 Open Declaration => "interface.dart"
 // F? Open Implementations  => "server.dart" | "browser.dart"
var foo = new Foo();

library.dart

import basic.dart;

interface class Foo {
  Foo();
}

basic.s.dart

env server;

import "dart:io";
import "interface.dart";

implementation class Foo {
  File _file;
  Foo() {
    file = new File();
  }
}

basic.w.dart

env web;

import "dart:html";
import "interface.dart";

implementation class Foo {
  Element _element;
  Foo() {
    _element = new DivElement();
  }
}

The expected behavior would be, I'm in a browser, I will use the library portion that states it is for the web. We could even use the part functionality.

But this should hide the complexity from the user of the library, since s/he shouldn't need to deal with it at all. Remember, we want to keep Dart the clean language it is, not add verbosity that is implied.

from dep-configured-imports.

seaneagan avatar seaneagan commented on May 28, 2024

I think an interface library can be supported via a pattern like:

library foo;

import (conditionally src/server.dart or src/browser.dart which both contain a FooImpl);

class Foo {
  const Foo() = FooImpl;
}

from dep-configured-imports.

lrhn avatar lrhn commented on May 28, 2024

This approach assumes a fixed number of environments, and doesn't expand to user defined configurations.
It also requires loading a library to check whether it matches the current environment, which isn't desirable.

from dep-configured-imports.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.