type
stringclasses 7
values | content
stringlengths 4
9.55k
| repo
stringlengths 7
96
| path
stringlengths 4
178
| language
stringclasses 1
value |
---|---|---|---|---|
ArrowFunction |
() => setTextModeEnabled(true) | jschuler/kogito-tooling | packages/chrome-extension/src/app/components/single/SingleEditorApp.tsx | TypeScript |
ArrowFunction |
(
props: DefaultSidePanelProps
): JSX.Element => {
const { onSidePanelItemClick } = props;
return (
<SidePanelItems type="desktop" onSidePanelItemClick={ onSidePanelItemClick }/> | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
ArrowFunction |
(props: MobileSidePanelProps): JSX.Element => {
const { children, onPusherClick, visible, onSidePanelItemClick } = props;
return (
<Sidebar.Pushable>
<Sidebar
animation="push"
visible={ visible }
>
<SidePanelItems type="mobile" onSidePanelItemClick={ onSidePanelItemClick }/>
</Sidebar>
<Sidebar.Pusher
onClick={ onPusherClick }
className="side-panel-pusher"
>
{ children }
</Sidebar.Pusher>
</Sidebar.Pushable> | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
ArrowFunction |
(props: SidePanelItemsProps): JSX.Element => {
const { type, onSidePanelItemClick } = props;
const activeRoute = (path: string) => {
const pathname = window.location.pathname;
const urlTokens = path.split("/");
return pathname.indexOf(urlTokens[1]) > -1 ? "active" : "";
};
return (
<Menu className={ `side-panel ${ type }` } | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
ArrowFunction |
(path: string) => {
const pathname = window.location.pathname;
const urlTokens = path.split("/");
return pathname.indexOf(urlTokens[1]) > -1 ? "active" : "";
} | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
ArrowFunction |
(route, index) => (
route.showOnSidePanel ?
<Menu.Item
as={ NavLink } | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
ArrowFunction |
(
props: SidePanelWrapperProps
): JSX.Element => {
const { mobileSidePanelVisibility, children, onSidePanelPusherClick, onSidePanelItemClick } = props;
return (
<>
<Responsive { ...Responsive.onlyMobile }>
<MobileSidePanel
onPusherClick={ onSidePanelPusherClick }
visible={ mobileSidePanelVisibility }
onSidePanelItemClick={ onSidePanelItemClick }
>
<Divider className="x1" hidden/>
<Container>{ children }</Container>
</MobileSidePanel>
</Responsive>
<Responsive as={ Container } minWidth={ Responsive.onlyTablet.minWidth }>
<Divider className="x2" hidden/>
<Grid>
<Grid.Row columns={ 2 }>
<Grid.Column tablet={ 6 } computer={ 4 }>
<DefaultSidePanel onSidePanelItemClick={ onSidePanelItemClick }/>
</Grid.Column>
<Grid.Column tablet={ 10 } computer={ 12 }>
{ children }
</Grid.Column>.
</Grid.Row>
</Grid>
</Responsive>
</> | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
InterfaceDeclaration | /**
* Default side panel component Prop types.
*/
interface DefaultSidePanelProps {
onSidePanelItemClick: () => void;
} | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
InterfaceDeclaration | /**
* Mobile side panel component Prop types.
*/
interface MobileSidePanelProps extends DefaultSidePanelProps {
children?: React.ReactNode;
onPusherClick: () => void;
visible: boolean;
} | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
InterfaceDeclaration | /**
* Side panel items component Prop types.
*/
interface SidePanelItemsProps {
onSidePanelItemClick: () => void;
type: "desktop" | "mobile";
} | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
InterfaceDeclaration | /**
* Side panel wrapper component Prop types.
*/
interface SidePanelWrapperProps {
children?: React.ReactNode;
onSidePanelItemClick: () => void;
onSidePanelPusherClick: () => void;
mobileSidePanelVisibility: boolean;
} | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
MethodDeclaration |
activeRoute(route | inthirakumaaran/identity-apps | apps/admin-portal/src/components/side-panel.tsx | TypeScript |
InterfaceDeclaration |
interface SvgrComponent extends React.FC<React.SVGAttributes<SVGElement>> {} | TimLuo465/rgl-dnd | src/typings.d.ts | TypeScript |
ClassDeclaration |
@Component({
selector: 'ngx-contract',
styleUrls: ['./delete-customer.scss'],
template: `
<nb-card>
<nb-card-header>
{{ title }}
<h6 class="close " aria-label="Close" (click)="dismiss()">
<span aria-hidden="true">×</span>
</h6>
</nb-card-header>
<nb-card-body>
<div>Do you want to delete id {{ this.id }}</div>
<div class="footer">
<button class="float-right btn btn-info" (click)="delete()">OK</button>
<button class="float-right btn btn-hint" (click)="dismiss()">Cancel</button>
</div>
</nb-card-body>
</nb-card>
`,
})
export class DeleteComponent implements OnInit {
id: String;
title: String;
constructor(protected ref: NbDialogRef<DeleteComponent>, private contractService: ContractService) {}
ngOnInit() {}
dismiss() {
this.ref.close();
}
async delete() {
let i = this.contractService.delete(this.id);
}
} | vothiphuongnga200997/travello | .history/src/app/pages/contract/delete-customer_20191005031707.ts | TypeScript |
MethodDeclaration |
dismiss() {
this.ref.close();
} | vothiphuongnga200997/travello | .history/src/app/pages/contract/delete-customer_20191005031707.ts | TypeScript |
MethodDeclaration |
async delete() {
let i = this.contractService.delete(this.id);
} | vothiphuongnga200997/travello | .history/src/app/pages/contract/delete-customer_20191005031707.ts | TypeScript |
FunctionDeclaration |
function isNode() {
if (typeof process === 'object') {
if (typeof process.versions === 'object') {
if (typeof process.versions.node !== 'undefined') {
return true;
}
}
}
return false;
} | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
function isUint8Array(object: any) {
return object instanceof Uint8Array && (!isNode() || !Buffer.isBuffer(object));
} | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
function isArrayBuffer(object: any) {
return object instanceof ArrayBuffer;
} | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
function isBuffer(object: any) {
if (!isNode()) {
return false;
}
return Buffer.isBuffer(object);
} | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
export function uncompress(compressed: Buffer): Buffer; | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
export function uncompress(compressed: Uint8Array): Uint8Array; | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
export function uncompress(compressed: ArrayBuffer): ArrayBuffer; | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
export function uncompress(compressed: any) {
if (!isUint8Array(compressed) && !isArrayBuffer(compressed) && !isBuffer(compressed)) {
throw new TypeError(TYPE_ERROR_MSG);
}
let uint8Mode = false;
let arrayBufferMode = false;
let buffer: Buffer;
if (isUint8Array(compressed)) {
uint8Mode = true;
buffer = Buffer.from(compressed.buffer, compressed.byteOffset, compressed.byteLength);
} else if (isArrayBuffer(compressed)) {
arrayBufferMode = true;
buffer = Buffer.from(compressed);
} else {
buffer = compressed;
}
const length = readUncompressedLength(buffer);
if (length === -1) throw new Error('Invalid Snappy bitstream');
const target: Buffer = Buffer.alloc(length);
if (!uncompressToBuffer(buffer, target)) {
throw new Error('Invalid Snappy bitstream');
}
if (uint8Mode) {
return new Uint8Array(target.buffer);
} else if (arrayBufferMode) {
return target.buffer;
} else {
return target;
}
} | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
export function compress(uncompressed: Buffer): Buffer; | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
export function compress(uncompressed: Uint8Array): Uint8Array; | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
export function compress(uncompressed: ArrayBuffer): ArrayBuffer; | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
FunctionDeclaration |
export function compress(uncompressed: any) {
if (!isUint8Array(uncompressed) && !isArrayBuffer(uncompressed) && !isBuffer(uncompressed)) {
throw new TypeError(TYPE_ERROR_MSG);
}
let uint8Mode = false;
let arrayBufferMode = false;
let buffer: Buffer;
if (isUint8Array(uncompressed)) {
uint8Mode = true;
buffer = Buffer.from(uncompressed.buffer, uncompressed.byteOffset, uncompressed.byteLength);
} else if (isArrayBuffer(uncompressed)) {
arrayBufferMode = true;
buffer = Buffer.from(uncompressed);
} else {
buffer = uncompressed;
}
const maxLength = maxCompressedLength(buffer);
const target: Buffer = Buffer.alloc(maxLength);
const length = compressToBuffer(buffer, target);
const array = target.buffer.slice(0, length);
if (uint8Mode) {
return new Uint8Array(array);
} else if (arrayBufferMode) {
return array;
} else {
return Buffer.from(array);
}
} | ChrisZieba/parquets | src/snappy/index.ts | TypeScript |
ArrowFunction |
() => {
let junoClient: JunoClient;
let gitHubOAuthService: GitHubOAuthService;
let originalDataExplorer: Explorer;
beforeEach(() => {
junoClient = new JunoClient();
gitHubOAuthService = new GitHubOAuthService(junoClient);
originalDataExplorer = window.dataExplorer;
window.dataExplorer = {
...originalDataExplorer,
} as Explorer;
window.dataExplorer.notebookManager = new NotebookManager();
window.dataExplorer.notebookManager.junoClient = junoClient;
window.dataExplorer.notebookManager.gitHubOAuthService = gitHubOAuthService;
});
afterEach(() => {
jest.resetAllMocks();
window.dataExplorer = originalDataExplorer;
originalDataExplorer = undefined;
gitHubOAuthService = undefined;
junoClient = undefined;
});
it("logout deletes app authorization and resets token", async () => {
const deleteAppAuthorizationCallback = jest.fn().mockReturnValue({ status: HttpStatusCodes.NoContent });
junoClient.deleteAppAuthorization = deleteAppAuthorizationCallback;
await gitHubOAuthService.logout();
expect(deleteAppAuthorizationCallback).toBeCalled();
expect(gitHubOAuthService.getTokenObservable()()).toBeUndefined();
});
it("resetToken resets token", () => {
gitHubOAuthService.resetToken();
expect(gitHubOAuthService.getTokenObservable()()).toBeUndefined();
});
it("startOAuth resets OAuth state", async () => {
let url: string;
const windowOpenCallback = jest.fn().mockImplementation((value: string) => {
url = value;
});
window.open = windowOpenCallback;
await gitHubOAuthService.startOAuth("scope");
expect(windowOpenCallback).toBeCalled();
const initialParams = new URLSearchParams(new URL(url).search);
expect(initialParams.get("state")).toBeDefined();
await gitHubOAuthService.startOAuth("another scope");
expect(windowOpenCallback).toBeCalled();
const newParams = new URLSearchParams(new URL(url).search);
expect(newParams.get("state")).toBeDefined();
expect(newParams.get("state")).not.toEqual(initialParams.get("state"));
});
it("finishOAuth updates token", async () => {
const data = { key: "value" };
const getGitHubTokenCallback = jest.fn().mockReturnValue({ status: HttpStatusCodes.OK, data });
junoClient.getGitHubToken = getGitHubTokenCallback;
const initialToken = gitHubOAuthService.getTokenObservable()();
const state = await gitHubOAuthService.startOAuth("scope");
const params: IGitHubConnectorParams = {
state,
code: "code",
};
await gitHubOAuthService.finishOAuth(params);
const updatedToken = gitHubOAuthService.getTokenObservable()();
expect(getGitHubTokenCallback).toBeCalledWith("code");
expect(initialToken).not.toEqual(updatedToken);
});
it("finishOAuth updates token to error if state doesn't match", async () => {
await gitHubOAuthService.startOAuth("scope");
const params: IGitHubConnectorParams = {
state: "state",
code: "code",
};
await gitHubOAuthService.finishOAuth(params);
expect(gitHubOAuthService.getTokenObservable()().error).toBeDefined();
});
it("finishOAuth updates token to error if unable to fetch token", async () => {
const getGitHubTokenCallback = jest.fn().mockReturnValue({ status: HttpStatusCodes.NotFound });
junoClient.getGitHubToken = getGitHubTokenCallback;
const state = await gitHubOAuthService.startOAuth("scope");
const params: IGitHubConnectorParams = {
state,
code: "code",
};
await gitHubOAuthService.finishOAuth(params);
expect(getGitHubTokenCallback).toBeCalledWith("code");
expect(gitHubOAuthService.getTokenObservable()().error).toBeDefined();
});
it("isLoggedIn returns false if resetToken is called", () => {
gitHubOAuthService.resetToken();
expect(gitHubOAuthService.isLoggedIn()).toBeFalsy();
});
it("isLoggedIn returns false if logout is called", async () => {
const deleteAppAuthorizationCallback = jest.fn().mockReturnValue({ status: HttpStatusCodes.NoContent });
junoClient.deleteAppAuthorization = deleteAppAuthorizationCallback;
await gitHubOAuthService.logout();
expect(gitHubOAuthService.isLoggedIn()).toBeFalsy();
});
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
() => {
junoClient = new JunoClient();
gitHubOAuthService = new GitHubOAuthService(junoClient);
originalDataExplorer = window.dataExplorer;
window.dataExplorer = {
...originalDataExplorer,
} as Explorer;
window.dataExplorer.notebookManager = new NotebookManager();
window.dataExplorer.notebookManager.junoClient = junoClient;
window.dataExplorer.notebookManager.gitHubOAuthService = gitHubOAuthService;
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
() => {
jest.resetAllMocks();
window.dataExplorer = originalDataExplorer;
originalDataExplorer = undefined;
gitHubOAuthService = undefined;
junoClient = undefined;
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
async () => {
const deleteAppAuthorizationCallback = jest.fn().mockReturnValue({ status: HttpStatusCodes.NoContent });
junoClient.deleteAppAuthorization = deleteAppAuthorizationCallback;
await gitHubOAuthService.logout();
expect(deleteAppAuthorizationCallback).toBeCalled();
expect(gitHubOAuthService.getTokenObservable()()).toBeUndefined();
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
() => {
gitHubOAuthService.resetToken();
expect(gitHubOAuthService.getTokenObservable()()).toBeUndefined();
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
async () => {
let url: string;
const windowOpenCallback = jest.fn().mockImplementation((value: string) => {
url = value;
});
window.open = windowOpenCallback;
await gitHubOAuthService.startOAuth("scope");
expect(windowOpenCallback).toBeCalled();
const initialParams = new URLSearchParams(new URL(url).search);
expect(initialParams.get("state")).toBeDefined();
await gitHubOAuthService.startOAuth("another scope");
expect(windowOpenCallback).toBeCalled();
const newParams = new URLSearchParams(new URL(url).search);
expect(newParams.get("state")).toBeDefined();
expect(newParams.get("state")).not.toEqual(initialParams.get("state"));
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
(value: string) => {
url = value;
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
async () => {
const data = { key: "value" };
const getGitHubTokenCallback = jest.fn().mockReturnValue({ status: HttpStatusCodes.OK, data });
junoClient.getGitHubToken = getGitHubTokenCallback;
const initialToken = gitHubOAuthService.getTokenObservable()();
const state = await gitHubOAuthService.startOAuth("scope");
const params: IGitHubConnectorParams = {
state,
code: "code",
};
await gitHubOAuthService.finishOAuth(params);
const updatedToken = gitHubOAuthService.getTokenObservable()();
expect(getGitHubTokenCallback).toBeCalledWith("code");
expect(initialToken).not.toEqual(updatedToken);
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
async () => {
await gitHubOAuthService.startOAuth("scope");
const params: IGitHubConnectorParams = {
state: "state",
code: "code",
};
await gitHubOAuthService.finishOAuth(params);
expect(gitHubOAuthService.getTokenObservable()().error).toBeDefined();
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
async () => {
const getGitHubTokenCallback = jest.fn().mockReturnValue({ status: HttpStatusCodes.NotFound });
junoClient.getGitHubToken = getGitHubTokenCallback;
const state = await gitHubOAuthService.startOAuth("scope");
const params: IGitHubConnectorParams = {
state,
code: "code",
};
await gitHubOAuthService.finishOAuth(params);
expect(getGitHubTokenCallback).toBeCalledWith("code");
expect(gitHubOAuthService.getTokenObservable()().error).toBeDefined();
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
() => {
gitHubOAuthService.resetToken();
expect(gitHubOAuthService.isLoggedIn()).toBeFalsy();
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
async () => {
const deleteAppAuthorizationCallback = jest.fn().mockReturnValue({ status: HttpStatusCodes.NoContent });
junoClient.deleteAppAuthorization = deleteAppAuthorizationCallback;
await gitHubOAuthService.logout();
expect(gitHubOAuthService.isLoggedIn()).toBeFalsy();
} | Azure/cosmos-explorer | src/GitHub/GitHubOAuthService.test.ts | TypeScript |
ArrowFunction |
(lang) => {
this.language = lang;
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
(result) => {
this.needCaptcha = result.isCaptchaNeed;
this.publicKey = result.publicKey;
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
(config) => {
this.socialConfig = config && config.social;
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
(config: any) => {
this.makePasswordSettings(config);
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
() => this.makePasswordSettings() | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
(r) => {
if (r === 'accept') {
this.registration();
}
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
(err) => {
console.info(err);
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
(key) => {
this.registerAccount.langKey = key;
this.makeLogins();
this.registerService.save(this.registerAccount).subscribe(() => {
this.success = true;
this.eventManager.broadcast({name: XM_EVENT_LIST.XM_REGISTRATION, content: ''});
},
(response) => this.processError(response));
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
() => {
this.success = true;
this.eventManager.broadcast({name: XM_EVENT_LIST.XM_REGISTRATION, content: ''});
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
(response) => this.processError(response) | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
(result) => {
this.publicKey = result.publicKey;
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ClassDeclaration |
@Component({
selector: 'xm-register',
templateUrl: './register.component.html',
})
export class RegisterComponent implements OnInit {
@Input() public config: any;
@ViewChild(ReCaptchaComponent, {static: false}) public captcha: ReCaptchaComponent;
public email: string;
public msisdn: string;
public nickname: string;
public confirmPassword: string;
public doNotMatch: string;
public error: string;
public errorEmailEmpty: string;
public errorUserExists: string;
public captchaRequired: string;
public registerAccount: any;
public success: boolean;
public modalRef: NgbModalRef;
public needCaptcha: boolean = false;
public language: string = 'en';
public publicKey: string;
public socialConfig: [];
public passwordSettings: PasswordSpec;
public patternMessage: string;
public passwordConfig: any;
constructor(private jhiLanguageService: JhiLanguageService,
private xmConfigService: XmConfigService,
private registerService: RegisterService,
private eventManager: JhiEventManager,
private modalService: NgbModal) {
this.jhiLanguageService.getCurrent().then((lang) => {
this.language = lang;
});
this.registerService.isCaptchaNeed().subscribe((result) => {
this.needCaptcha = result.isCaptchaNeed;
this.publicKey = result.publicKey;
});
}
public ngOnInit(): void {
this.success = false;
this.registerAccount = {};
this.xmConfigService.getUiConfig().subscribe((config) => {
this.socialConfig = config && config.social;
});
this.xmConfigService
.getPasswordConfig()
.subscribe((config: any) => {
this.makePasswordSettings(config);
}, () => this.makePasswordSettings());
}
public register(): void {
if (this.registerAccount.password !== this.confirmPassword) {
this.doNotMatch = 'ERROR';
} else {
if (this.config && this.config.privacyAndTermsEnabled) {
const modalRef = this.modalService.open(PrivacyAndTermsDialogComponent, {
size: 'lg',
backdrop: 'static',
});
modalRef.componentInstance.config = this.config;
modalRef.result.then((r) => {
if (r === 'accept') {
this.registration();
}
}).catch((err) => {
console.info(err);
});
} else {
this.registration();
}
}
}
public handleCorrectCaptcha($event: any): void {
this.registerAccount.captcha = $event;
this.captchaRequired = null;
}
public handleCaptchaExpired(_$event: any): void {
this.registerAccount.captcha = null;
}
private registration(): void {
this.doNotMatch = null;
this.error = null;
this.errorUserExists = null;
this.errorEmailEmpty = null;
this.captchaRequired = null;
this.jhiLanguageService.getCurrent().then((key) => {
this.registerAccount.langKey = key;
this.makeLogins();
this.registerService.save(this.registerAccount).subscribe(() => {
this.success = true;
this.eventManager.broadcast({name: XM_EVENT_LIST.XM_REGISTRATION, content: ''});
},
(response) => this.processError(response));
});
}
private processError(response: any): void {
this.success = null;
if (response.status === 400 && response.error.error === 'error.login.already.used') {
this.errorUserExists = 'ERROR';
} else if (response.status === 400 && response.error.error === 'error.captcha.required') {
this.captchaRequired = 'ERROR';
this.needCaptcha = true;
this.registerService.isCaptchaNeed().subscribe((result) => {
this.publicKey = result.publicKey;
});
} else {
this.error = 'ERROR';
}
if (this.captcha) {this.captcha.reset(); }
}
private makeLogins(): void {
this.registerAccount.logins = [];
// email login
this.registerAccount.logins.push({
typeKey: 'LOGIN.EMAIL',
login: this.email,
});
// nickname login
if (this.nickname) {
this.registerAccount.logins.push({
typeKey: 'LOGIN.NICKNAME',
login: this.nickname,
});
}
// phone number login
if (this.msisdn) {
this.registerAccount.logins.push({
typeKey: 'LOGIN.MSISDN',
login: this.msisdn,
});
}
}
private makePasswordSettings(config?: any): void {
this.passwordConfig = config;
this.passwordSettings = this.xmConfigService.mapPasswordSettings(config);
if (this.passwordSettings.patternMessage) {
this.patternMessage = this.xmConfigService.updatePatternMessage(this.passwordSettings.patternMessage);
}
}
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
MethodDeclaration |
public ngOnInit(): void {
this.success = false;
this.registerAccount = {};
this.xmConfigService.getUiConfig().subscribe((config) => {
this.socialConfig = config && config.social;
});
this.xmConfigService
.getPasswordConfig()
.subscribe((config: any) => {
this.makePasswordSettings(config);
}, () => this.makePasswordSettings());
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
MethodDeclaration |
public register(): void {
if (this.registerAccount.password !== this.confirmPassword) {
this.doNotMatch = 'ERROR';
} else {
if (this.config && this.config.privacyAndTermsEnabled) {
const modalRef = this.modalService.open(PrivacyAndTermsDialogComponent, {
size: 'lg',
backdrop: 'static',
});
modalRef.componentInstance.config = this.config;
modalRef.result.then((r) => {
if (r === 'accept') {
this.registration();
}
}).catch((err) => {
console.info(err);
});
} else {
this.registration();
}
}
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
MethodDeclaration |
public handleCorrectCaptcha($event: any): void {
this.registerAccount.captcha = $event;
this.captchaRequired = null;
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
MethodDeclaration |
public handleCaptchaExpired(_$event: any): void {
this.registerAccount.captcha = null;
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
MethodDeclaration |
private registration(): void {
this.doNotMatch = null;
this.error = null;
this.errorUserExists = null;
this.errorEmailEmpty = null;
this.captchaRequired = null;
this.jhiLanguageService.getCurrent().then((key) => {
this.registerAccount.langKey = key;
this.makeLogins();
this.registerService.save(this.registerAccount).subscribe(() => {
this.success = true;
this.eventManager.broadcast({name: XM_EVENT_LIST.XM_REGISTRATION, content: ''});
},
(response) => this.processError(response));
});
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
MethodDeclaration |
private processError(response: any): void {
this.success = null;
if (response.status === 400 && response.error.error === 'error.login.already.used') {
this.errorUserExists = 'ERROR';
} else if (response.status === 400 && response.error.error === 'error.captcha.required') {
this.captchaRequired = 'ERROR';
this.needCaptcha = true;
this.registerService.isCaptchaNeed().subscribe((result) => {
this.publicKey = result.publicKey;
});
} else {
this.error = 'ERROR';
}
if (this.captcha) {this.captcha.reset(); }
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
MethodDeclaration |
private makeLogins(): void {
this.registerAccount.logins = [];
// email login
this.registerAccount.logins.push({
typeKey: 'LOGIN.EMAIL',
login: this.email,
});
// nickname login
if (this.nickname) {
this.registerAccount.logins.push({
typeKey: 'LOGIN.NICKNAME',
login: this.nickname,
});
}
// phone number login
if (this.msisdn) {
this.registerAccount.logins.push({
typeKey: 'LOGIN.MSISDN',
login: this.msisdn,
});
}
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
MethodDeclaration |
private makePasswordSettings(config?: any): void {
this.passwordConfig = config;
this.passwordSettings = this.xmConfigService.mapPasswordSettings(config);
if (this.passwordSettings.patternMessage) {
this.patternMessage = this.xmConfigService.updatePatternMessage(this.passwordSettings.patternMessage);
}
} | ffluffyhedgehog/xm-webapp | src/app/shared/register/register.component.ts | TypeScript |
ArrowFunction |
() => (
<SvgIcon viewBox="0 0 512 512">
<linearGradient
gradientUnits | 435352980/tw-qc-static | src/svgIcons/ArmorSvg.tsx | TypeScript |
FunctionDeclaration |
function colRef<T>(ref: CollectionPredicate<T>): CollectionReference<T> {
const db = getFirestore();
return typeof ref === 'string' ? (collection(db, ref) as CollectionReference<T>) : ref;
} | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
FunctionDeclaration |
function docRef<T>(ref: DocPredicate<T>): DocumentReference<T> {
if (typeof ref === 'string') {
const pathParts = ref.split('/');
const documentId = pathParts.pop();
const collectionString = pathParts.join('/');
return doc<T>(colRef(collectionString), documentId);
} else {
return ref;
}
} | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
FunctionDeclaration | // not exporting lite versions of getCollection nor getDocument on client in favor of using full firestore cache-first versions.
async function getDocument<T>(ref: DocPredicate<T>): Promise<T> {
const docSnap = await getDoc(docRef(ref));
return docSnap.exists() ? { ...(docSnap.data() as T), id: docSnap.id } : null;
} | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
FunctionDeclaration | /**
* Use when wanting to receive back promises that will resolve or error when internet is flaky, unlike regular firestore methods which won't resolve right away in these situations.
* Be sure to import firestore methods such as serverTimestamp() from firebase/firestore/lite otherwise you will receive errors */
export function addOnline<T>(
ref: CollectionPredicate<T>,
data: T,
opts: {
abbreviate?: boolean;
} = {}
): Promise<DocumentReference<T>> {
return addDoc(colRef(ref), {
...data,
[opts.abbreviate ? 'ca' : 'createdAt']: serverTimestamp(),
[opts.abbreviate ? 'cb' : 'createdBy']: getUid(),
[opts.abbreviate ? 'ua' : 'updatedAt']: serverTimestamp(),
[opts.abbreviate ? 'ub' : 'updatedBy']: getUid(),
});
} | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
FunctionDeclaration | /**
* Use when wanting to receive back promises that will resolve or error when internet is flaky, unlike regular firestore methods which won't resolve right away in these situations.
* Be sure to import firestore methods such as serverTimestamp() from firebase/firestore/lite otherwise you will receive errors */
export async function setOnline<T>(
ref: DocPredicate<T>,
data: T,
opts: {
abbreviate?: boolean;
merge?: boolean;
} = {}
): Promise<void> {
const snap = await getDocument(ref);
return await (snap
? updateOnline(ref, data)
: setDoc(
docRef(ref),
{
...data,
[opts.abbreviate ? 'ca' : 'createdAt']: serverTimestamp(),
[opts.abbreviate ? 'cb' : 'createdBy']: getUid(),
[opts.abbreviate ? 'ua' : 'updatedAt']: serverTimestamp(),
[opts.abbreviate ? 'ub' : 'updatedBy']: getUid(),
},
{ merge: opts.merge }
));
} | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
FunctionDeclaration | /**
* Use when wanting to receive back promises that will resolve or error when internet is flaky, unlike regular firestore methods which won't resolve right away in these situations.
* Be sure to import firestore methods such as serverTimestamp() from firebase/firestore/lite otherwise you will receive errors */
export async function updateOnline<T>(
ref: DocPredicate<T>,
data: Partial<T>,
opts: {
abbreviate?: boolean;
} = {}
): Promise<void> {
// @ts-ignore
return updateDoc(docRef(ref), {
...data,
[opts.abbreviate ? 'ua' : 'updatedAt']: serverTimestamp(),
[opts.abbreviate ? 'ub' : 'updatedBy']: getUid(),
});
} | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
FunctionDeclaration | /**
* Use when wanting to receive back promises that will resolve or error when internet is flaky, unlike regular firestore methods which won't resolve right away in these situations.
* Be sure to import firestore methods such as serverTimestamp() from firebase/firestore/lite otherwise you will receive errors */
export function deleteDocumentOnline<T>(ref: DocPredicate<T>): Promise<void> {
return deleteDoc(docRef(ref));
} | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
ArrowFunction |
() => {
const u = get(authState);
return (u && u.uid) || 'anonymous'; // 'anonymous' allows support messages to be saved by non-logged-in users
} | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
TypeAliasDeclaration |
type CollectionPredicate<T> = string | CollectionReference<T>; | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
TypeAliasDeclaration |
type DocPredicate<T> = string | DocumentReference<T>; | jacobbowdoin/sveltefire-ts | src/lib/client/firestore-lite.ts | TypeScript |
ArrowFunction |
() => {
ws.send(JSON.stringify(Message.ConnectRequest));
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
ArrowFunction |
(event) => {
this.setState({ elem: this.props.connectFailed });
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
ArrowFunction |
(payload: T) => this.sendMessage(role, label, payload, successor) | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
ArrowFunction |
(error?: any) => this.cancel(error) | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
ArrowFunction |
(event: FunctionArguments<DOMEvents[K]>) => {
if (used) {
return;
}
used = true;
try {
const result = handler(event);
if (result instanceof Promise) {
result.then(send).catch(cancel);
} else {
send(result);
}
} catch (error) {
cancel(error);
}
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
ArrowFunction |
child => (
React.cloneElement(child as React.ReactElement, props)
) | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
ClassDeclaration |
export default class Session extends React.Component<Props, Partial<Transport>> {
constructor(props: Props) {
super(props);
this.state = {
ws: undefined
};
}
componentDidMount() {
// Set up WebSocket connection
this.setState({
ws: new WebSocket(this.props.endpoint),
});
}
render() {
const { ws } = this.state;
return ws === undefined
? this.props.waiting
: <P1 ws={ws} {...this.props} />;
}
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
ClassDeclaration |
class P1 extends React.Component<Props & Transport, ComponentState> {
private messageQueue: RoleToMessageQueue
private handlerQueue: RoleToHandlerQueue
constructor(props: Props & Transport) {
super(props);
this.state = {
elem: props.waiting,
};
// Set up message and handler queues
this.messageQueue = {
[Roles.Peers.P2]: [], [Roles.Peers.Svr]: [],
};
this.handlerQueue = {
[Roles.Peers.P2]: [], [Roles.Peers.Svr]: [],
};
// Bind functions
this.onReceiveInit = this.onReceiveInit.bind(this);
this.onCloseInit = this.onCloseInit.bind(this);
this.onClose = this.onClose.bind(this);
this.onReceiveMessage = this.onReceiveMessage.bind(this);
this.buildSendElement = this.buildSendElement.bind(this);
this.registerReceiveHandler = this.registerReceiveHandler.bind(this);
this.advance = this.advance.bind(this);
this.cancel = this.cancel.bind(this);
this.terminate = this.terminate.bind(this);
}
componentDidMount() {
const { ws } = this.props;
ws.onmessage = this.onReceiveInit;
// Send connection message
ws.onopen = () => {
ws.send(JSON.stringify(Message.ConnectRequest));
};
// Handle error
ws.onerror = (event) => {
this.setState({ elem: this.props.connectFailed });
}
ws.onclose = this.onCloseInit;
}
// ===============
// Session joining
// ===============
private onReceiveInit(message: MessageEvent) {
const { ws } = this.props;
ws.onmessage = this.onReceiveMessage;
ws.onclose = this.onClose;
this.advance(SendState.S17);
}
private onCloseInit({ code, wasClean, reason }: CloseEvent) {
if (!wasClean) {
// Not closed properly
this.setState({ elem: this.props.connectFailed });
return;
}
switch (code) {
case Cancellation.Receive.ROLE_OCCUPIED: {
this.processCancellation(Roles.Self, 'role occupied');
return;
}
default: {
// Unsupported code
this.processCancellation(Roles.Server, reason);
return;
}
}
}
// ===============
// EFSM operations
// ===============
private advance(state: State) {
if (isSendState(state)) {
const View = this.props.states[state];
this.setState({
elem: <View factory={this.buildSendElement} />
});
return;
}
if (isReceiveState | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
TypeAliasDeclaration |
type RoleToMessageQueue = Roles.PeersToMapped<any[]>; | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
TypeAliasDeclaration |
type RoleToHandlerQueue = Roles.PeersToMapped<ReceiveHandler[]>; | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
TypeAliasDeclaration | // ==============
// Component type
// ==============
type Props = {
endpoint: string,
states: {
S17: Constructor<S17>,
S19: Constructor<S19>,
S21: Constructor<S21>,
S20: Constructor<S20>,
S18: Constructor<S18>,
},
waiting: React.ReactNode,
connectFailed: React.ReactNode,
cancellation: (role: Roles.All, reason?: any) => React.ReactNode,
}; | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
TypeAliasDeclaration |
type Transport = {
ws: WebSocket
}; | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
TypeAliasDeclaration |
type ComponentState = {
elem: React.ReactNode
}; | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
MethodDeclaration |
componentDidMount() {
// Set up WebSocket connection
this.setState({
ws: new WebSocket(this.props.endpoint),
});
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
MethodDeclaration |
render() {
const { ws } = this.state;
return ws === undefined
? this.props.waiting
: <P1 ws={ws} {...this.props} />;
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
MethodDeclaration |
componentDidMount() {
const { ws } = this.props;
ws.onmessage = this.onReceiveInit;
// Send connection message
ws.onopen = () => {
ws.send(JSON.stringify(Message.ConnectRequest));
};
// Handle error
ws.onerror = (event) => {
this.setState({ elem: this.props.connectFailed });
}
ws.onclose = this.onCloseInit;
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
MethodDeclaration | // ===============
// Session joining
// ===============
private onReceiveInit(message: MessageEvent) {
const { ws } = this.props;
ws.onmessage = this.onReceiveMessage;
ws.onclose = this.onClose;
this.advance(SendState.S17);
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
MethodDeclaration |
private onCloseInit({ code, wasClean, reason }: CloseEvent) {
if (!wasClean) {
// Not closed properly
this.setState({ elem: this.props.connectFailed });
return;
}
switch (code) {
case Cancellation.Receive.ROLE_OCCUPIED: {
this.processCancellation(Roles.Self, 'role occupied');
return;
}
default: {
// Unsupported code
this.processCancellation(Roles.Server, reason);
return;
}
}
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
MethodDeclaration | // ===============
// EFSM operations
// ===============
private advance(state: State) {
if (isSendState(state)) {
const View = this.props.states[state];
this.setState({
elem: <View factory={this.buildSendElement} />
});
return;
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
MethodDeclaration |
if (isReceiveState | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
MethodDeclaration |
return <K extends keyof DOMEvents>(eventLabel: K, handler: EventHandler<T, K>) | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
MethodDeclaration |
render() {
const props = {
[eventLabel as string]: (event: FunctionArguments<DOMEvents[K]>) => {
if (used) {
return;
}
used = true;
try {
const result = handler(event);
if (result instanceof Promise) {
result.then(send).catch(cancel);
} else {
send(result);
}
} catch (error) {
cancel(error);
}
}
};
return React.Children.map(this.props.children, child => (
React.cloneElement(child as React.ReactElement, props)
));
} | STScript-2020/cc21-artifact | case-studies/Battleships/client/src/Battleships/P1/P1.tsx | TypeScript |
ArrowFunction |
(letter: string): string => "_" + letter.toLowerCase() | Raisess/i3bcks-gen | src/Parser.ts | TypeScript |
ArrowFunction |
(item: string): string => item.trim() | Raisess/i3bcks-gen | src/Parser.ts | TypeScript |
ClassDeclaration |
export default class Parser {
private parsedBlocks: Array<string> = [
"command=/usr/share/i3blocks/$BLOCK_NAME\nseparator_block_width=20\nmarkup=none\n\n",
];
constructor(private blocks: Array<Block>) {}
public parse(): string {
for (const block of this.blocks) {
let parsedBlock: string = `[${block.name}]`;
const blockEntries: Array<[string, unknown]> = Object.entries(block);
for (const [key, value] of blockEntries) {
if (key !== "name" && key !== "command" && key !== "evalType") {
parsedBlock += this.parseField(key, value);
} else if (key === "command") {
if (block.evalType === "shell") {
parsedBlock += this.parseField(key, value);
} else if (block.evalType === "node") {
const expression: string = this.functionToString(
value as () => unknown
);
parsedBlock += this.parseField(
key,
this.evaluateExpression(expression)
);
}
}
}
this.parsedBlocks.push(parsedBlock);
}
// Need to add a blank space a the end of generated file,
// if don't, the last block just doesn't work.
this.parsedBlocks.push(" ");
return this.parsedBlocks.join("\n\n");
}
private parseField(key: string, value: unknown): string {
return `\n${key.replace(
/[A-Z]/g,
(letter: string): string => "_" + letter.toLowerCase()
)}=${value}`;
}
private functionToString(funct: () => unknown): string {
const expression: string = funct
.toString()
.split(/\n/)
.map((item: string): string => item.trim())
.join("");
return expression;
}
private evaluateExpression(expression: string): string {
return `node -e 'console.log((${expression})());'`;
}
} | Raisess/i3bcks-gen | src/Parser.ts | TypeScript |
TypeAliasDeclaration |
export type Block = {
name: string;
label?: string;
align?: string;
color?: string;
fullText?: string;
shortText?: string;
instance?: string;
interval?: number | "once" | "persist" | "repeat";
minWidth?: string;
separator?: boolean;
separatorBlockWidth?: number;
signal?: number;
urgent?: string;
command?: string | (() => void);
evalType?: "node" | "shell";
}; | Raisess/i3bcks-gen | src/Parser.ts | TypeScript |
MethodDeclaration |
public parse(): string {
for (const block of this.blocks) {
let parsedBlock: string = `[${block.name}]`;
const blockEntries: Array<[string, unknown]> = Object.entries(block);
for (const [key, value] of blockEntries) {
if (key !== "name" && key !== "command" && key !== "evalType") {
parsedBlock += this.parseField(key, value);
} else if (key === "command") {
if (block.evalType === "shell") {
parsedBlock += this.parseField(key, value);
} else if (block.evalType === "node") {
const expression: string = this.functionToString(
value as () => unknown
);
parsedBlock += this.parseField(
key,
this.evaluateExpression(expression)
);
}
}
}
this.parsedBlocks.push(parsedBlock);
}
// Need to add a blank space a the end of generated file,
// if don't, the last block just doesn't work.
this.parsedBlocks.push(" ");
return this.parsedBlocks.join("\n\n");
} | Raisess/i3bcks-gen | src/Parser.ts | TypeScript |
MethodDeclaration |
private parseField(key: string, value: unknown): string {
return `\n${key.replace(
/[A-Z]/g,
(letter: string): string => "_" + letter.toLowerCase()
)}=${value}`;
} | Raisess/i3bcks-gen | src/Parser.ts | TypeScript |
MethodDeclaration |
private functionToString(funct: () => unknown): string {
const expression: string = funct
.toString()
.split(/\n/)
.map((item: string): string => item.trim())
.join("");
return expression;
} | Raisess/i3bcks-gen | src/Parser.ts | TypeScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.