0.1.0 • Published 4 years ago
sova-lib v0.1.0
nn-componenet-lib
json-server --watch db.json to start JSON server
Rules: Component Creation :
General
- If you file having template or setup function then only it should have .vue extension
- If you component does not maintain any state(data) means it should be functional component
- reactive/refs should be used carefully. it should not be repetitive.
- We planned to use shallow reactive in future. This improves performance.
#keywords
- defaultData - It holds default data.It should be defined outside default export scope so that it will be initialised only one.
- Data - This is not reactive just to combile default data and props
- cData - holds all attributes with reactivity. This will be passed across base to child so any can access attributess.
- cMethod - Hold public methods of the component. This will be passed across base to concrete.
- publicMethods - all the public methods should be defined inside this method.
- attributes - all the props need to pass to components are grouped under this object. (check 8th point in Comp Impl)
- EventType - all the user defined event type should be defined here. 8 cEvents - this is holder for events defined from child to root. So that we can access root event in child
Components implementation
- All Components should implement setup hook. This took props and context as arguments
- Create data objects that add default properties and then suppose same property come is props it will override default const data = { ...defaultData, ...props.attributes };
- All components or base components should inherit nn-root-comp.js. It will take data and context as arguments. Inherits Syntax: const { cData, cMethods ,cEvents } = nnInputField(data, context);
- Then call publicMethods(cData , cMethods); append all the public methods to cMthods object using .operator const publicmethods = (cData, cMethods) => { // all pubilc methods shoud append with dot opperator cMethods.updateOptions }"
- Return of setup hook Concrete file(with.vue extension) -> return { ...toRefs(cData), ...cMethods }; Other class -> return { cData, ...cMethods };
- Method Over ride Always we are appending methods to Cmethod so it will defaulty override super methods
- Call Super If you want to call super method , assign super method to variable before overriding and use it later " const publicmethods = (cData, cMethods) => { const superupdateValues = cMethods.updateValues; // assgin super method cMethods.updateValues = () => { cMethods.setAttribute({ label: ""Update From Component select"", }); superupdateValues(); // caling super metod } }" 8.Mention all Event Type in a EventType constant as follows, " const EventType = { CHANGE: ""fw_change"" };"
Emit event change inside any method or listen default event and then emitt custom event. " // do custom stuff here (validation,suppress etc) context.emit(cEvents.CHANGE, event);"
Attributes - we could not able inherit props , so we keep single object for attributes and all the props from template should be given in single object " props: { attributes: { type: Object, default: () => {} } }," <nnDropDown ref="PincodeSelect" :attributes="{ label: 'Default App' } /> template usage
Compoenet usage in app template , lets take drop down component which ref is "PincodeSelect" & label as Attribute
<nnDropDown ref="PincodeSelect" :attributes="{ label: 'Default App' } @fw_change="onChangeEmpSelect" />
1. ref is simillar to id
2. attributes , al the attributes are grouped under this object
" 3. Add Listener to custom event. @fw_change=""onChangeEmpSelect"" define onChangeEmpSelect insde app.js"
Compoenet access in app.js
- Update Attributes " aMethod.getComponent(""PincodeSelect"").setAttribute({ label: ""Pincode App"", });"
- Get Attributes aMethod.getComponent("PincodeSelect").getAttribute("options")
- Invoke methods
App Implementation
- All Apps should implement setup hook. This took props and context as arguments // To-Do .. Some concepts difficult to implemet after vue 3 update working on it
To Bundle
run -> npm run bundle
once bundle folder is generated you can use the libary
#see client.html for reference
0.1.0
4 years ago