1.0.32 • Published 8 years ago

@tandem/sandbox v1.0.32

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

Kitchen sink example:

import { Kernel } from "@tandem/common";
import { SyntheticWindow, SyntheticDocument } from "@tandem/synthetic-browser";
import {
  Sandbox,
  Dependency,
  FileCacheItem,
  LocalFileSystem,
  DependencyGraph,
  ISyntheticObject,
  LocalFileResolver,
  FileSystemProvider,
  FileEditorProvider,
  FileResolverProvider,
  DependencyGraphProvider,
  ContentEditorFactoryProvider,
  DependencyLoaderFactoryProvider,
} from "@tandem/sandbox";


const kernel = new Kernel(
  new DependencyGraphProvider(),
  new FileEditorProvider(),
  new FileSystemProvider(new LocalFileSystem()),
  new FileResolverProvider(new LocalFileResolver()),
  new DependencyLoaderFactoryProvider("text/css", CSSDependencyLoader),
  new ContentEditorFactoryProvider("text/css", CSSContentEditor),
);

// fetch the dependency graph singleton
const dependencyGraph: DependencyGraph = DependencyGraphProvider.getInstance("webpack", kernel);

const sandbox = new Sandbox(deps, function createGlobal() {

  // global environment context -- browser, node, etc
  return new SyntheticWindow();
});

// create an dependency entry -- all dependencies, and nested dependencies
// be dependency up into this object.
const fileDependency: Dependency = dependencyGraph.getDependency("file:///path/to/local/file.html");

// execute the file dependency. Re-execute if the dependency changes
const fakeDocument: SyntheticDocument = await sandbox.open(fileDependency);

const edit = fakeDocument.body.createEdit().appendChild(fakeDocument.createTextNode("hello world")));

// the synthetic object edit maintains a reference back to the source file -- where it patches changes --
// file:///path/to/local/file.html in this case.
FileEditorProvider.getInstance(deps).applyMutations(...edit.mutations);

Diffing & patching synthetic objects example:

import { SyntheticWindow } from "@tandem/synthetic-browser";
import { SyntheticObjectTreeEditor } from "@tandem/sandbox";

const { document } = new SyntheticWindow();
document.body.innerHTML = `Hello World`;

const documentClone = document.cloneNode(true);
documentClone.body.innerHTML = `Hello Again!`;

// create a diff from a newer node
const edit = document.createEdit().fromDiff(documentClone);

// apply the edit to the original document
new SyntheticObjectTreeEditor(document).applyMutations(...edit.mutations);

// this also works
// edit.applyMutationsTo(document);
1.0.32

8 years ago

1.0.31

8 years ago

1.0.29

8 years ago

1.0.28

8 years ago

1.0.27

8 years ago

1.0.26

8 years ago

1.0.22

8 years ago

1.0.21

8 years ago

1.0.20

8 years ago

1.0.18

8 years ago

1.0.17

9 years ago

1.0.16

9 years ago

1.0.15

9 years ago

1.0.14

9 years ago

1.0.13

9 years ago

1.0.12

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.0

9 years ago