0

I'm seeing some weird behavior in Dart. My goal is to only serve static assets if a build/web Dir exists.

1- The following works:

Cascade cc;
if(new Directory(buildPath).existsSync() )
{
  cc = new Cascade().add(apiHandler).add(fHandler);
} else {
  cc = new Cascade().add(apiHandler);
}

2- The following does not work:

  Cascade cc = new Cascade().add(apiHandler);
  if( new Directory(buildPath).existsSync() )
  {
    cc.add(fHandler);
  }

Question: The example in scenario 1 works fine. In the second example, when i add fHandler, how come none of its associated routes ever get handled?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jack Murphy
  • 2,952
  • 1
  • 30
  • 49

1 Answers1

4

The Cascade class is immutable so the add method returns a new instance. Your second code block is assuming the current instance is modified

You need to add the cc =

cc = cc.add(..)
Anders
  • 1,337
  • 1
  • 8
  • 17