本文整理汇总了TypeScript中rxjs/operators.dematerialize函数的典型用法代码示例。如果您正苦于以下问题:TypeScript dematerialize函数的具体用法?TypeScript dematerialize怎么用?TypeScript dematerialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dematerialize函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Notification
observable1 = constructorZone1.run(() => {
const notifA = new Notification('N', 'A');
const notifB = new Notification('N', 'B');
const notifE = new Notification('E', void 0, error);
const materialized = of(notifA, notifB, notifE as any);
return materialized.pipe(dematerialize());
});
示例2: it
it('should dematerialize stream does not emit', () => {
const e1 = hot('----|', NO_VALUES);
const e1subs = '^ !';
const expected = '----|';
expectObservable(e1.pipe(dematerialize())).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例3: intercept
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// array in local storage for registered users
let sampleData: any = '{"_id" : "5bc4c4dfb4c0630145163c71","_schema" : "https://data.nist.gov/od/dm/nerdm-schema/v0.2#","topic" : [],"references" : [{"refType" : "IsReferencedBy","_extensionSchemas" : ["https://data.nist.gov/od/dm/nerdm-schema/v0.2#/definitions/DCiteReference"],"@id" : "#ref:10.1007/s10694-016-0646-7","@type" : [ "deo:BibliographicReference"],"location" : "https://doi.org/10.1007/s10694-016-0646-7"}],"_extensionSchemas" : [ "https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/PublicDataResource"],"landingPage" : "https://www.nist.gov/el/fire-research-division-73300/national-fire-research-laboratory-73306/measurement-behavior-steel","dataHierarchy" : [{"filepath" : "NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx"}, {"filepath" : "NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx.sha256"}, {"filepath" : "NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx"}, {"filepath" : "NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx.sha256"}],"title" : "Measurement of the Behavior of Steel Beams under Localized Fire Exposure","theme" : [ "Structural fire resistance"],"inventory" : [{"forCollection" : "","descCount" : 5,"childCollections" : [],"childCount" : 5,"byType" : [{"descCount" : 5,"forType" : "dcat:Distribution","childCount" : 5}, {"descCount" : 1,"forType" : "nrd:Hidden","childCount" : 1}, {"descCount" : 2,"forType" : "nrdp:ChecksumFile","childCount" : 2}, {"descCount" : 2,"forType" : "nrdp:DataFile","childCount" : 2}, {"descCount" : 4,"forType" : "nrdp:DownloadableFile","childCount" : 4}]}],"programCode" : [ "006:045"],"@context" : [ "https://data.nist.gov/od/dm/nerdm-pub-context.jsonld", {"@base" : "ark:/88434/mds0147p62"}],"description" : ["A total of nine localized fire tests on steel beams were designed and conducted in the National Fire Research Laboratory as part of its commissioning project, including thermal tests (Tests 1 through 5) and four-point bending test at ambient (Test 6) and elevated temperatures (Tests 7 through 9). All the tested specimens were nominally 6.2-m long W16Ă26 beams made of ASTM A992 steel. Each specimen was supported by one of the two following connections: (i) simple support (Tests 1 through 8), and (ii) double-angles bolted to laterally braced support columns (Test 9). The midspan of each specimen was exposed to an open-flame fire using the 1-m2 natural gas burners. The burner was located 1.1 m below the bottom flange of the beam at midspan. A four-point flexural loading scheme was used to apply concentrated forces at two locations 2.44 m apart around midspan. The data included temperatures, the heat release rates from the burner, and structural measurements including forces, displacements and strains. The Type B standard uncertainties in various measurements were also included. Overall, the test results showed that the heating rate of the specimen was sensitive to the prescribed heat release rate-time relationship. However, the thermal gradient developed in the fire-exposed cross sections of the beam never achieved linearity under the localized fire exposure. Regardless of the connection types and fire conditions (i.e., steady-state or transient-state fire), the beams exhibited a similar behavior and failure mode. When subjected to combined fire and flexural loads, the beam specimens exhibited the lateral-torsional buckling followed by runaway vertical displacements at midspan. Additional details of experimental procedures and uncertainty analysis for this experimental series are provided in the following publications:1) Zhang, C., Choe, L., Gross, J., Ramesh, S., Bundy, M. (2017). Engineering Approach for Designing a Thermal Test of Real-scale Steel Beam Exposed to Localized Fire. Fire Technology, Vol 53, Issue 4, pp 1535-1554. DOI: 10.1007/s10694-016-0646-72) Choe, L., Ramesh, S., Zhang, C., Gross, J. (2016). The Performance of Structural Steel Beams Subjected to a Localized Fire. The 9th International Conference on Structures in Fire (SiF 16), June 8-10, 2016, Princeton, NJ."],"language" : ["en"],"bureauCode" : [ "006:55"],"contactPoint" : {"hasEmail" : "mailto:lisa.choe@nist.gov","fn" : "Lisa Choe"},"accessLevel" : "public","@id" : "ark:/88434/mds0147p62","publisher" : {"@type" : "org:Organization","name" : "National Institute of Standards and Technology"},"doi" : "doi:10.18434/M37H4G","keyword" : [ "steel beam; localized fire; thermal and mechanical behavior; experimental test"],"license" : "https://www.nist.gov/open/license","modified" : "2017-08-14","ediid" : "5BD6911D381AB2E3E0531A57068151FA1869","components" : [ {"filepath" : "NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx","mediaType" : "text/plain","downloadURL" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx","@id" : "cmps/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx","@type" : [ "nrdp:DataFile", "nrdp:DownloadableFile", "dcat:Distribution"],"_extensionSchemas" : [ "https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/DataFile"]}, {"description" : "SHA-256 checksum value for NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx","algorithm" : {"tag" : "sha256","@type" : "Thing"},"filepath" : "NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx.sha256","mediaType" : "text/plain","downloadURL" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx.sha256","@id" : "cmps/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx.sha256","@type" : ["nrdp:ChecksumFile", "nrdp:DownloadableFile", "dcat:Distribution"],"_extensionSchemas" : [ "https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/ChecksumFile"]},{"filepath" : "NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx","mediaType" : "text/plain","downloadURL" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx","@id" : "cmps/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx","@type" : [ "nrdp:DataFile", "nrdp:DownloadableFile", "dcat:Distribution"],"_extensionSchemas" : [ "https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/DataFile"]}, {"description" : "SHA-256 checksum value for NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx","algorithm" : {"tag" : "sha256","@type" : "Thing"},"filepath" : "NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx.sha256","mediaType" : "text/plain","downloadURL" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx.sha256","@id" : "cmps/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx.sha256","@type" : [ "nrdp:ChecksumFile", "nrdp:DownloadableFile", "dcat:Distribution"],"_extensionSchemas" : [ "https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/ChecksumFile"]}, {"accessURL" : "https://doi.org/10.18434/M37H4G","@id" : "#doi:10.18434/M37H4G","@type" :["nrd:Hidden","dcat:Distribution"]}],"@type" : [ "nrdp:PublicDataResource"]}';
let bundlePlanRes : any = '{"status" : "warnings","messages" : [ "Some urls are not added due to unsupported host.", "Additional message here." ],"notIncluded" : [ {"filePath" : "/1894/license2.pdf","downloadUrl" : "https://project-open-data.cio.gov/v1.1/schema","message" : "Not valid Url."} ],"bundleNameFilePathUrl" : [ {"bundleName" : "testdownload-1.zip","includeFiles" : [ {"filePath" :"5BD6911D381AB2E3E0531A57068151FA1869/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx","downloadUrl" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx"},{"filePath" :"5BD6911D381AB2E3E0531A57068151FA1869/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx.sha256","downloadUrl" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx.sha256"} ]},{"bundleName": "testdownload-2.zip","includeFiles" : [ {"filePath" : "5BD6911D381AB2E3E0531A57068151FA1869/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx","downloadUrl" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx"},{"filePath" : "5BD6911D381AB2E3E0531A57068151FA1869/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx.sha256","downloadUrl" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx.sha256"} ]} ],"postEach" : "_bundle"}';
// let bundlePlanRes : any = '{"status" : "warnings","messages" : [ "Some urls are not added due to unsupported host.", "Additional message here." ],"bundleNameFilePathUrl" : [ {"bundleName" : "testdownload-1.zip","includeFiles" : [ {"filePath" :"5BD6911D381AB2E3E0531A57068151FA1869/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx","downloadUrl" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx"},{"filePath" :"5BD6911D381AB2E3E0531A57068151FA1869/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx.sha256","downloadUrl" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_08112017.xlsx.sha256"} ]},{"bundleName": "testdownload-2.zip","includeFiles" : [ {"filePath" : "5BD6911D381AB2E3E0531A57068151FA1869/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx","downloadUrl" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx"},{"filePath" : "5BD6911D381AB2E3E0531A57068151FA1869/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx.sha256","downloadUrl" : "https://s3.amazonaws.com/nist-midas/1856/NFRL_LocalizedFireTest_SteelBeam_09012017.xlsx.sha256"} ]} ],"postEach" : "_bundle"}';
// let httpRequest: any[] = [
// {"url":"https://s3.amazonaws.com/nist-midas/1858/20170213_PowderPlate2_Pad.zip","body":null,"reportProgress":true,"withCredentials":false,"responseType":"blob","method":"GET","headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"params":{"updates":null,"cloneFrom":null,"encoder":{},"map":null},"urlWithParams":"https://s3.amazonaws.com/nist-midas/1858/20170213_PowderPlate2_Pad.zip"}
// ];
// wrap in delayed observable to simulate server api call
return of(null).pipe(mergeMap(() => {
// get bundlePlan
if (request.url.endsWith('/od/ds/_bundle_plan') && request.method === 'POST') {
return of(new HttpResponse({ status: 200, body: JSON.parse(bundlePlanRes) }));
}
if (request.url.endsWith('/rmm/records/5BD6911D381AB2E3E0531A57068151FA1869') && request.method === 'GET') {
return of(new HttpResponse({ status: 200, body: JSON.parse(sampleData) }));
}
// get bundle
// if (request.url.endsWith('/od/ds/_bundle') && request.method === 'POST') {
// // return new Observable(observer => {
// // observer.next(this.testDataService.getBundle('https://s3.amazonaws.com/nist-midas/1858/20170213_PowderPlate2_Pad.zip', params););
// // observer.complete();
// // });
// // return this.testDataService.getBundle('https://s3.amazonaws.com/nist-midas/1858/20170213_PowderPlate2_Pad.zip', bundlePlanRes);
// console.log("Handling /od/ds/_bundle:");
// const duplicate = request.clone({
// method: 'get'
// })
// return next.handle(request);
// }
// pass through any requests not handled above
return next.handle(request);
}))
// call materialize and dematerialize to ensure delay even if an error is thrown (https://github.com/Reactive-Extensions/RxJS/issues/648)
.pipe(materialize())
.pipe(delay(500))
.pipe(dematerialize());
}
示例4: mergeMap
mergeMap(source$ =>
source$.pipe(
exhaustMap(resolveEffectSource),
map(output => {
verifyOutput(output, this.errorHandler);
return output.notification;
}),
filter(
(notification): notification is Notification<Action> =>
notification.kind === 'N'
),
dematerialize()
)
示例5: dematerialize1
dematerialize1() {
// emit next and error notifications
const source = from([
Notification.createNext('SUCCESS!'),
Notification.createError('ERROR!')
]).pipe(
// turn notification objects into notification values
dematerialize()
);
// output: 'NEXT VALUE: SUCCESS' 'ERROR VALUE: 'ERROR!'
const subscription = source.subscribe({
next: val => console.log(`NEXT VALUE: ${val}`),
error: val => console.log(`ERROR VALUE: ${val}`)
});
}
示例6: intercept
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
let testUser = { id: 1, username: 'test', password: 'test', firstName: 'Steve', lastName: 'Palmer' };
// wrap in delayed observable to simulate server api call
return of(null).pipe(mergeMap(() => {
/* mock http request for AuthenticationService.login */
// authenticate
if (request.url.endsWith('/users/authenticate') && request.method === 'POST') {
if (request.body.username === testUser.username && request.body.password === testUser.password) {
// if login details are valid return 200 OK with a fake jwt token
let body = {
id: testUser.id,
username: testUser.username,
firstName: testUser.firstName,
lastName: testUser.lastName,
token: 'fake-jwt-token'
};
return of(new HttpResponse({ status: 200, body }));
} else {
// else return 400 bad request
return throwError({ error: { message: 'Username or password is incorrect' } });
}
}
/* mock http request for UserService.getAll */
// get users
if (request.url.endsWith('/users') && request.method === 'GET') {
// check for fake auth token in header and return users if valid, this security is implemented server side in a real application
if (request.headers.get('Authorization') === 'Bearer fake-jwt-token') {
return of(new HttpResponse({ status: 200, body: [testUser] }));
} else {
// return 401 not authorised if token is null or invalid
return throwError({ error: { message: 'Unauthorised' } });
}
}
// pass through any requests not handled above
return next.handle(request);
}))
// call materialize and dematerialize to ensure delay even if an error is thrown (https://github.com/Reactive-Extensions/RxJS/issues/648)
.pipe(materialize())
.pipe(delay(500))
.pipe(dematerialize());
}
示例7: asDiagram
asDiagram('dematerialize')('should dematerialize an Observable', () => {
const values = {
a: '{x}',
b: '{y}',
c: '{z}',
d: '|'
};
const e1 = hot('--a--b--c--d-|', values);
const expected = '--x--y--z--|';
const result = e1.pipe(
map((x: string) => {
if (x === '|') {
return Notification.createComplete();
} else {
return Notification.createNext(x.replace('{', '').replace('}', ''));
}
}),
dematerialize()
);
expectObservable(result).toBe(expected);
});
示例8: it
it('should enforce types', () => {
const o = of(Notification.createNext('foo')).pipe(dematerialize(() => {})); // $ExpectError
});
示例9: higherOrder
export function dematerialize<T>(this: Observable<Notification<T>>): Observable<T> {
return higherOrder()(this) as Observable<T>;
}
示例10: intercept
//.........这里部分代码省略.........
// if login details are valid return 200 OK with user details and fake jwt token
let user = filteredUsers[0];
let body = {
id: user.id,
username: user.username,
firstName: user.firstName,
lastName: user.lastName,
token: 'fake-jwt-token'
};
return of(new HttpResponse({ status: 200, body: body }));
} else {
// else return 400 bad request
return throwError('Username or password is incorrect');
}
}
// get users
if (request.url.endsWith('/api/users') && request.method === 'GET') {
// check for fake auth token in header and return users if valid, this security is implemented server side in a real application
if (request.headers.get('Authorization') === 'Bearer fake-jwt-token') {
return of(new HttpResponse({ status: 200, body: users }));
} else {
// return 401 not authorised if token is null or invalid
return throwError('Unauthorised');
}
}
// get user by id
if (request.url.match(/\/api\/users\/\d+$/) && request.method === 'GET') {
// check for fake auth token in header and return user if valid, this security is implemented server side in a real application
if (request.headers.get('Authorization') === 'Bearer fake-jwt-token') {
// find user by id in users array
let urlParts = request.url.split('/');
let id = parseInt(urlParts[urlParts.length - 1]);
let matchedUsers = users.filter(user => { return user.id === id; });
let user = matchedUsers.length ? matchedUsers[0] : null;
return of(new HttpResponse({ status: 200, body: user }));
} else {
// return 401 not authorised if token is null or invalid
return throwError('Unauthorised');
}
}
// create user
if (request.url.endsWith('/api/users') && request.method === 'POST') {
// get new user object from post body
let newUser = request.body;
// validation
let duplicateUser = users.filter(user => { return user.username === newUser.username; }).length;
if (duplicateUser) {
return throwError('Username "' + newUser.username + '" is already taken');
}
// save new user
newUser.id = users.length + 1;
users.push(newUser);
localStorage.setItem('users', JSON.stringify(users));
// respond 200 OK
return of(new HttpResponse({ status: 200 }));
}
// delete user
if (request.url.match(/\/api\/users\/\d+$/) && request.method === 'DELETE') {
// check for fake auth token in header and return user if valid, this security is implemented server side in a real application
if (request.headers.get('Authorization') === 'Bearer fake-jwt-token') {
// find user by id in users array
let urlParts = request.url.split('/');
let id = parseInt(urlParts[urlParts.length - 1]);
for (let i = 0; i < users.length; i++) {
let user = users[i];
if (user.id === id) {
// delete user
users.splice(i, 1);
localStorage.setItem('users', JSON.stringify(users));
break;
}
}
// respond 200 OK
return of(new HttpResponse({ status: 200 }));
} else {
// return 401 not authorised if token is null or invalid
return throwError('Unauthorised');
}
}
// pass through any requests not handled above
return next.handle(request);
}))
// call materialize and dematerialize to ensure delay even if an error is thrown (https://github.com/Reactive-Extensions/RxJS/issues/648)
.pipe(materialize())
.pipe(delay(500))
.pipe(dematerialize());
}
示例11: intercept
//.........这里部分代码省略.........
}));
}
}
/*
*
* Update Password
*
*/
if (request.url.match('https://mock-api-server/auth') && request.method === 'PUT') {
// Check if password matches password confimation
if (request.body.password !== request.body.password_confirmation) {
return of(this.registerError(
request.body.email,
{ password_confirmation: ['does not match Password'] }
));
}
const user = this.getAuthUser(request);
if (user && user.password === request.body.password) {
this.users[(user.id - 1)].password = request.body.password;
localStorage.setItem('users', JSON.stringify(this.users));
return of(new HttpResponse<any>({
headers: this.getHeaders(user.email),
status: 200,
url: 'https://mock-api-server/auth',
body: {
status: 'success',
data: {
id: user.id,
email: user.email,
uid: user.email,
provider: 'email',
name: null,
nickname: null,
image: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString()
}
}
}));
} else {
return of(new HttpResponse<any>({
status: 401,
url: 'https://mock-api-server/auth',
body: {
success: false,
errors: ['Invalid login credentials']
}
}));
}
}
/*
*
* Access Private Resouce
*
*/
if (request.url.match('https://mock-api-server/private_resource') && request.method === 'GET') {
const user = this.getAuthUser(request);
if (user) {
return of(new HttpResponse<any>({
headers: this.getHeaders(user.email),
status: 200,
url: 'https://mock-api-server/auth/private_resource',
body: {
data: 'Private Content for ' + user.email
}
}));
} else {
return of(new HttpResponse<any>({
status: 401,
url: 'https://mock-api-server/auth/private_resource',
body: {
success: false,
errors: ['Invalid login credentials']
}
}));
}
}
// pass through any requests not handled above
return next.handle(request);
}))
// call materialize and dematerialize to ensure delay even if an
// error is thrown (https://github.com/Reactive-Extensions/RxJS/issues/648)
.pipe(materialize())
.pipe(delay(500))
.pipe(dematerialize());
}