vue-me
This package helps you to seperate concerns within your Vue Class Components. At this state of development it can be used for fast prototyping or small applications.
Due to lack of testing it is not recommended to used this library for business applications.
Heavily inspired by the recompose package provided by acdlite.
Installation
npm i vue-me - or - yarn add vue-me
Quickstart
If you've never built a Vue app before or simply haven't found the time to setup a boilerplate, feel free to clone or fork the project below to get started.
git clone https://github.com/nine36/vue-me-starterkit.git
Example
ExampleComponent.js
; { return <div> <div>thistitle</div> <button onClick= { this; }> Change </button> </div> ; } ExampleComponent;
App.js
Api
withAxios
Demo (Use the axios server example locally)
Syntax
Parameter | Type | Description | Required |
---|---|---|---|
endpoint | String | Endpoint for requests | true |
method | String | Request method (GET) | true |
state | String | State identifier | true |
handler | String | Handler identifier | true |
Description
Retrieve data from your server with axios and use it in your component.
Usage
... return <div> thisallUsers <button onClick=thisfetchAllUsers>Fetch users</button> </div> ... ExampleComponent;
withHandlers
https://codesandbox.io/s/k58jnnp60v
DemoSyntax
Parameter | Type | Description | Required |
---|---|---|---|
props | Object | Component props | false |
values | Object | Handler arguments | false |
Description
Declare handlers to manage more complex logic or async operations.
Usage
...; ... return <div> thisusername <button onClick=thisgetUser>Fetch users</button> </div> ... ExampleComponent;
withLifecycles
https://codesandbox.io/s/yk72yvnx91
DemoSyntax
Parameter | Type | Description | Required |
---|---|---|---|
props | Object | Component props | false |
Description
Declare lifecycles to inject into your component.
Usage
... ExampleComponent;
withNormalizer
https://codesandbox.io/s/4qmy255kmx
DemoSyntax
Parameter | Type | Description | Required |
---|---|---|---|
state | String | State identifier | true |
data | Object, Array | Target data | true |
objectIdentifier | String | Object identifier | true |
newProperty | String | New property | true |
Description
This function helps you to normalize your data. It can also be used to replace object identifiers with property values and add the old identifiers as new properties.
Usage
const dataSet1 = uuid: 'xxx-1' name: 'Socrates' uuid: 'xxx-2' name: 'Archimedes' const dataSet2 = 'wise': uuid: 'xxx-1' name: 'Socrates' 'also-wise': uuid: 'xxx-2' name: 'Archimedes' return <div> Object Object </div> ExampleComponent;
withProps
https://codesandbox.io/s/4lqo1ywnn9
DemoSyntax
Parameter | Type | Description | Required |
---|---|---|---|
name | String | Property identifier | true |
defaultValue | String | Default value | true |
required | Boolean | Property is required | true |
Description
Declare component props.
Usage
return <div> thisusername </div> const ChildContainer = ExampleComponent; return <div> /* renders the default 'Socrates' */ <ChildContainer /> /* renders 'Archimedes' */ <ChildContainer user= name: 'Archimedes' /> </div>
withService
https://codesandbox.io/s/0oxn09rq4l
DemoSyntax
Parameter | Type | Description | Required |
---|---|---|---|
state | String | State identifier | true |
handler | String | Handler identifier | true |
service | Function | Service | true |
Description
Hook up your service to a local state and handler
Usage
;... return <div> thisusername <button onClick= this>Fetch user</button> </div> ... ExampleComponent;
withState
https://codesandbox.io/s/ym632o20pj
DemoSyntax
Parameter | Type | Description | Required |
---|---|---|---|
state | String | State identifier | true |
mutation | String | Mutation identifier | true |
initialState | any | Initial state | true |
Description
Declare local state and state mutations.
Usage
... return <div> thisusername <button onClick= this>Fetch users</button> </div> ... ExampleComponent;