#########################################################
#########################################################
--- DEPRECATED ---
- install dependencies
npm i
- move
node_modules
folder to a folder above the current one (Pls do not ask why ?:-)) - start the app by
npm start
- go to
http://localhost:8080/#login?domain=user&page=login
npm run dev
for dev mode hot setup (in this case go tohttp://localhost:8080/#login?domain=user&page=login
)
- An attempt to make app creation faster and segregate concerns involved
- Steps to be there in an App development could be
-
- create views (
presentation layer
)
- create views (
-
- mention stores array to watch in the view
script
portion useStoreWatcherMixin
- mention stores array to watch in the view
-
- hook up
events
into those views usingevent-manager\evens
config file
- hook up
-
- keep
state
always at a centralstore
(inspired by Flux architectures)
- keep
-
- make the above process run with any view technology, and with and framework (as long as it's Javascript)
-
- discourage
events
tohandler
binding within views. Keep allhandlers
at a seperate place in codebase(probably addable by a different developer)
- discourage
-
- discourage internal component
state
.Alsways operate on & keep watchingstate
kept at a global location. maintain watching of interestedstate
parts. No need to watch entire state for one update
- discourage internal component
-
- This is not Flux, but has borrowed many things from Flux & redux
- This is not PubSub only, but some part of it is
- Here's a mind-map of the system. A more detailed arch-diagram will be there as things evolve
import StoreWatcher from '../event-manager/mixins/storex'
<comp1>
<div>
<p> Hello World </p>
.... ...
</div>
</comp1>
let self = this
// for validations
// - add a validationform
// - add a validate function in the handlers['<tag-name>'] section to set result
// into state.<store>.<validationform>.validated property
self.stores = ['user'] // stores to watch
self.validationform = ['loginform'] // validation form . this will have validated field
// for store watching
// import StoreWatcher from ../../event-manager/mixins/storex
// self.mixin(StoreWatcher)
self.mixin(StoreWatcher)
- Handlers
-
- Each
View
will have one or more handlers it will interact with
- Each
-
Handlers
are where logic will be written (including DOM selectors) and value fetching.
-
handlers.js
will need be modified to add your logic. Logic will look like -
var handlers = {}
handlers['login'] = {}
handlers['login'].handleLogin = function (data, store, cb, event) {
let context = this
data.userId = document.querySelector('[data-is="' + data.page + '"] ' + 'input#userid').value
data.userPassword = document.querySelector('[data-is="' + data.page + '"] ' + 'input#password').value
if (data.userId === 'saurshaz' && data.userPassword === 'password') {
store.setState('user', 'userId', '')
store.setState('user', 'userPassword', '')
store.setState('user', 'me', data.userId)
store.setState('user', 'authStatus', true)
// todo : the screen shall ideally change now
} else {
store.setState('user', 'userId', data.userId)
store.setState('user', 'userPassword', data.userPassword)
store.setState('user', 'me', data.userId)
store.setState('user', 'authStatus', false)
}
cb(null, this)
}
....
....
and so on.. multiple entries
- data, store, cb, event are the inputs
- You'll get data - domain name and page name
- cb will be the flow return callback that u will use. expects (err, res)
- store will be the centrat store for the app (covered below)
- event is something that will seldom be needed to be touched (Advanced usage)
-
Store
-
- Each
View
will be watching none or manystores
(that are defined in theStoreWatcherMixin
in theView
layer component)
- Each
-
- You just need to add the store structure for your view in the universal Store JSON in
store.json
- You just need to add the store structure for your view in the universal Store JSON in
-
- store.js relavent code will look like -
let state = { global: {}, fyler: {request: '',requestjson: {}, response: '', err: ''}, user: {authStatus: false, userId: '', userPassword: '', loginform: {validated: false}}, misc: {} }
-
- Other than this, nothing needs be touched in store.js
-
Events
-
- this will be the configurable
events
matching map for eachview
with all it'sevents
andhandlers
- this will be the configurable
-
- basically you'll declare in JSON terms, different
events
and associatedhandlers
that you want to bind to in aview
layer
- basically you'll declare in JSON terms, different
-
events.js
relavent code will look like -
let eventsConfig = {}
// login components config eventsConfig.login = [] eventsConfig.login.push({ selector: { nodename: 'BUTTON',// type of node in capitals nodeid: 'submitLogin'// id value }, event: 'click',// what event handler: 'handleLogin'// handler callable on this event })
eventsConfig.login.push({ selector: { nodename: 'BUTTON',// type of node in capitals nodeid: 'resetLogin'// id value }, event: 'click',// what event handler: 'handleResetLogin'// handler callable on this event })
-
Thanks