Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions emulation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { fork, allSettled } from 'effector'

import './src/models/init'
import { app } from './src/models/app'
import {fetchUsersFx, updateUsersTableFx, $firebaseUsers} from './src/models/users'
import {signIn} from './src/models/auth'

const emails = [
'ewaters@hotmail.com',
'alias@aol.com',
'temmink@gmail.com',
'rfoley@att.net',
'yruan@me.com',
'parents@gmail.com',
'shrapnull@att.net',
'solomon@msn.com',
'chrisk@gmail.com',
'grolschie@mac.com',
'jschauma@hotmail.com',
'pplinux@gmail.com',
'ryanshaw@aol.com',
'corrada@me.com',
'mailarc@comcast.net',
'gravyface@comcast.net',
'willg@yahoo.ca',
'gemmell@live.com',
'mahbub@gmail.com',
'yenya@aol.com',
'solomon@live.com',
'miltchev@optonline.net',
'evans@outlook.com',
'leslie@hotmail.com',
'afeldspar@msn.com',
'portele@optonline.net',
'choset@outlook.com',
'sburke@gmail.com',
'tellis@gmail.com',
'mrsam@sbcglobal.net',
'loscar@optonline.net',
'vmalik@sbcglobal.net',
'mdielmann@yahoo.com',
'karasik@mac.com',
'pajas@mac.com',
'chunzi@outlook.com',
'lipeng@yahoo.ca',
'nacho@verizon.net',
'mailarc@outlook.com',
'ovprit@hotmail.com',
'demmel@yahoo.ca',
'mschwartz@live.com',
'salesgeek@att.net',
'haddawy@msn.com',
'novanet@optonline.net',
'themer@me.com',
'hellfire@gmail.com',
'csilvers@icloud.com',
'sabren@outlook.com',
'webdragon@comcast.net',
'ideguy@yahoo.ca',
'phish@comcast.net',
'moinefou@yahoo.ca',
'drolsky@comcast.net',
'tokuhirom@sbcglobal.net',
'pkplex@sbcglobal.net',
'jsnover@icloud.com',
'jbryan@icloud.com',
'ismail@aol.com',
'tezbo@live.com',
'miturria@comcast.net',
'daveed@yahoo.ca',
'yamla@optonline.net',
'jdhedden@verizon.net',
'odlyzko@yahoo.com',
'rogerspl@hotmail.com',
'sburke@msn.com',
'cparis@optonline.net',
'janneh@me.com',
'vlefevre@gmail.com',
'heroine@gmail.com',
'vsprintf@icloud.com',
'tkrotchko@outlook.com',
'graham@comcast.net',
'dburrows@optonline.net',
'russotto@outlook.com',
'singh@aol.com',
'lstaf@sbcglobal.net',
'pakaste@icloud.com',
'fwiles@yahoo.ca',
'jbuchana@comcast.net',
'gknauss@att.net',
'drjlaw@icloud.com',
'rbarreira@yahoo.com',
'danneng@hotmail.com',
'jdhedden@yahoo.ca',
'louise@att.net',
'papathan@me.com',
'ghost@aol.com',
'mcraigw@comcast.net',
'jfreedma@icloud.com',
'jhardin@icloud.com',
'raines@yahoo.ca',
'hikoza@comcast.net',
'kodeman@me.com',
'rhavyn@hotmail.com',
'burniske@optonline.net',
'mallanmba@hotmail.com',
'bester@icloud.com',
'dprice@outlook.com',
'dialworld@icloud.com',
'rgox@msn.com',
'mxugle@aol.com',
'cled@icloud.com',
'mxugle@gmail.com',
'inn@aol.com',
'eck@verizon.net',
'curi@optonline.net',
'och@me.com',
'nnen@mac.com',
'thomas@verizon.net',
'owell@att.net'
]
const password = '123456'
const testScope = fork(app)

async function startFunc() {
await Promise.all([emails.map(async (email) => {
await allSettled(signIn, {
scope: testScope,
params: {email, password}
})
})])
await allSettled(fetchUsersFx, {
scope: testScope
})
const users = testScope.getState($firebaseUsers)
await Promise.all([Object.keys(users).map(async (id) => {
await allSettled(updateUsersTableFx, {
scope: testScope,
params: { id, tableID: 'first-table' }
})
})])

}

startFunc()
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "index.js",
"scripts": {
"start": "parcel public/index.html --no-cache",
"build": "parcel build -d dist --no-autoinstall --public-url /try public/index.html"
"build": "parcel build -d dist --no-autoinstall --public-url /try public/index.html",
"build:server": "parcel build --target=node ./emulation.ts",
"start:server": "node dist/emulataion"
},
"keywords": [
"effector"
Expand Down
10 changes: 6 additions & 4 deletions src/models/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {createEffect} from 'effector'
import {createDomain} from 'effector'
import { createGate } from 'effector-react'

import { Config } from './types'

export const initAppFx = createEffect<Config, unknown>()
export const app = createDomain()

export const showErrorFx = createEffect<string, unknown>()
export const initAppFx = app.createEffect<Config, unknown>()

export const showErrorFx = app.createEffect<string, unknown>()

export const AppGate = createGate()

export const Route = createGate<{ name: string }>()
export const Route = createGate<{ name: string }>()
9 changes: 8 additions & 1 deletion src/models/app/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { initializeApp } from 'firebase'
import { forward } from 'effector'

import {
initAppFx, showErrorFx, AppGate, Route
app, initAppFx, showErrorFx, AppGate, Route
} from './'

import { fetchUsersFx } from '../users'
Expand Down Expand Up @@ -52,4 +52,11 @@ forward({

Route.state.updates.watch(({name}) => {
history.pushState({}, '', `/${name}`)
})

app.onCreateEffect(fx => {
fx.failData.watch(err => {
console.error(`Error in ${fx.shortName}`)
console.error(err)
})
})
28 changes: 14 additions & 14 deletions src/models/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { createEvent, createEffect, createStore } from 'effector'
import { app } from '../app'

import { User, Credentials } from './types'

export const gSignIn = createEvent()
export const gSignIn = app.createEvent()

export const signIn = createEvent<Credentials>()
export const signIn = app.createEvent<Credentials>()

export const logout = createEvent<string>()
export const logout = app.createEvent<string>()

export const updateSignInForm = createEvent<{ value: string; fieldName: string }>()
export const updateSignInForm = app.createEvent<{ value: string; fieldName: string }>()

export const checkAuth = createEvent<User | null>()
export const checkAuth = app.createEvent<User | null>()

export const restoredAuth = createEvent<User>()
export const restoredAuth = app.createEvent<User>()

export const manageGmailProviderFx = createEffect<void, User>()
export const manageGmailProviderFx = app.createEffect<void, User>()

export const manageEmailProviderFx = createEffect<Credentials, User>()
export const manageEmailProviderFx = app.createEffect<Credentials, User>()

export const signUpViaEmailFx = createEffect<Credentials, { email: string }>()
export const signUpViaEmailFx = app.createEffect<Credentials, { email: string }>()

export const checkAuthFx = createEffect<void, unknown>()
export const checkAuthFx = app.createEffect<void, unknown>()

export const dropUserAuthFx = createEffect<string, unknown>()
export const dropUserAuthFx = app.createEffect<string, unknown>()

export const $user = createStore<User>({
export const $user = app.createStore<User>({
email: ''
})

export const $signInForm = createStore<Credentials>({
export const $signInForm = app.createStore<Credentials>({
email: '',
password: ''
})
6 changes: 3 additions & 3 deletions src/models/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createEvent, createStore} from 'effector'
import { app } from '../app'

export const redirect = createEvent<string>()
export const redirect = app.createEvent<string>()

export const $router = createStore<string[]>([])
export const $router = app.createStore<string[]>([])
12 changes: 6 additions & 6 deletions src/models/tables/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {createStore, createEvent} from 'effector'
import { app } from '../app'

export const updateCurrentIDandStage = createEvent<{ ID: string, stage: number }>()
export const updateCurrentIDandStage = app.createEvent<{ ID: string, stage: number }>()

export const updateStage = updateCurrentIDandStage.map(({ stage }) => stage)

export const $currentConnectID = createStore<string>('first-table')
export const $currentConnectID = app.createStore<string>('first-table')

export const $tableIDs = createStore<string[]>([
export const $tableIDs = app.createStore<string[]>([
'first-table',
'second-table',
'third-table',
Expand All @@ -30,6 +30,6 @@ export const $tableIDs = createStore<string[]>([

export const $tablesCount = $tableIDs.map((ids) => ids.length)

export const $tableCapacity = createStore(6)
export const $tableCapacity = app.createStore(6)

export const $stage = createStore(2)
export const $stage = app.createStore(2)
16 changes: 8 additions & 8 deletions src/models/users/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {createEvent, createEffect, createStore} from 'effector';
import {app} from '../app'

import { UsersMap, TableIDUsersMap, FirebaseUser } from './types'

export const changeUserTable = createEvent<string>()
export const updateUsers = createEvent<UsersMap>()
export const changeUserTable = app.createEvent<string>()
export const updateUsers = app.createEvent<UsersMap>()

export const fetchUsersFx = createEffect<void, UsersMap>()
export const addUserFx = createEffect<FirebaseUser, string[]>()
export const updateUsersTableFx = createEffect<{ id: string; tableID: string}, unknown>()
export const deleteUserFx = createEffect<string, unknown>()
export const fetchUsersFx = app.createEffect<void, UsersMap>()
export const addUserFx = app.createEffect<FirebaseUser, string[]>()
export const updateUsersTableFx = app.createEffect<{ id: string; tableID: string}, unknown>()
export const deleteUserFx = app.createEffect<string, unknown>()

export const $firebaseUsers = createStore<UsersMap>({});
export const $firebaseUsers = app.createStore<UsersMap>({});
export const $users = $firebaseUsers.map((fUsers) =>
Object.keys(fUsers).map((id) => fUsers[id])
)
Expand Down