This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The MIT License (MIT) | |
* | |
* Copyright (c) 2013 Thom Seddon | |
* Copyright (c) 2010 Google | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>A single-spa application</title> | |
</head> | |
<body> | |
<div id="cool-app"></div> | |
<script src="root-application.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import singleSpaAngular1 from 'single-spa-angular1'; | |
import angular from 'angular'; | |
import './app.module.js'; | |
import './routes.js'; | |
const domElementGetter = () => document.getElementById('cool-app'); | |
const angularLifecycles = singleSpaAngular1({ | |
angular, | |
domElementGetter, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// single-spa will import this file and call the exported lifecyle functions | |
let user; | |
export function bootstrap() { | |
return fetch('/api/users/0') | |
.then(response => response.json()) | |
.then(json => user = json); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* NOTE: that this code was written for https://github.com/CanopyTax and some parts might not be suitable for the generic use case. | |
It assumes that string data can be passed as both a property or an html attribute, and it prefers properties over attributes for everything. | |
USAGE: | |
- <x-foo attr1="'string'" /> | |
- <button is="my-button" /> | |
- <x-foo attr2="objOnScope" /> | |
*/ | |
import angular from 'angular'; | |
import {forEach, kebabCase, includes} from 'lodash'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The goal of the following code is to render the text “Copied!” when you click on a div. | |
After two seconds, you want to change the text to say “Something else.” | |
However, there is a bug which makes “Something else” never render. The reason why is that | |
React considers the StyledDiv to be a new type of element every time that Parent rerenders. | |
And one of React's reconciliation heuristics is to unmount/remount whenever the top level | |
returned child is a different type of element. So by the time the setTimeout happens, we are calling | |
setState on an already unmounted component. A new Child component has been created, with the initial state saying | |
"Copied!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const parcel = singleSpa.mountRootParcel(parcelConfig, parcelProps) | |
// First wait for mounting to finish | |
parcel.mountPromise.then(() => { | |
// Then re-render the parcel | |
const newProps = {foo: 'bar'} | |
return parcel.update(newProps) | |
}).then(() => { | |
// Then unmount the parcel | |
return parcel.unmount() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The things imported with ES6 are things we want to execute right up front. | |
// The things required below are things we want to execute only when someone needs them. | |
// Switching between the two impacts performance. In general, it's better to be lazy with | |
// executing code, but there are some things we need to do right up front. | |
import SystemJS from 'systemjs' | |
if (window.sofeManifest) { | |
SystemJS.config(sofeManifest) | |
delete window.sofeManifest | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as isActive from './child-app-active.functions.js'; | |
import * as singleSpa from 'single-spa' | |
// Main-content apps | |
singleSpa.registerApplication('workflow-ui', () => SystemJS.import('workflow-ui!sofe'), isActive.workflowUI); | |
singleSpa.registerApplication('end-user-forms-ui', () => SystemJS.import('end-user-forms-ui!sofe'), isActive.endUserFormsUI); | |
singleSpa.registerApplication('sme-qa-ui', () => SystemJS.import('sme-qa-ui!sofe'), isActive.smeQAUI); | |
singleSpa.registerApplication('letters-ui', () => SystemJS.import('letters-ui!sofe'), isActive.lettersUI); | |
singleSpa.registerApplication('docs-ui', () => SystemJS.import('docs-ui!sofe'), isActive.docsUI); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Util functions | |
*/ | |
/* Use this function to check that the hash begins with a certain prefix | |
*/ | |
export function hashPrefix(location, ...prefixes) { | |
return prefixes.some(prefix => location.hash.indexOf(`#/${prefix}`) === 0); | |
} | |
/* App-specific implementations that determine if they are active or not. |
OlderNewer