@wcardinal/wcardinal
v2.1.0
Published
Winter Cardinal client-side libraries
Downloads
174
Maintainers
Readme
Winter Cardinal is a library for real-time web applications build on top of the Spring framework. It is designed for making single-page applications stable against unintended network/server failures. The controller class and its fields defined on a server will be synchronized with clones on browsers in real time. Also enables us to call methods defined on the controller class from browsers.
// Java
import org.wcardinal.controller.annotation.Controller;
import org.wcardinal.controller.annotation.Callable;
@Controller
class MyController {
@Autowired
SLong field;
@Callable
String hello( String name ){
return "Hello, "+name;
}
}
<!-- HTML -->
<script src="./my-controller"></script>
<script>
myController.field.get(); // Gets a field value
myController.field.set( 128 ); // Changes a field value
// Calls `hello( String )` method
myController.hello( 'John' ).then(( result ) => {
console.log( result ); // Prints 'Hello, John'
});
</script>
Installation
Gradle
dependencies {
compile 'com.github.winter-cardinal:winter-cardinal:latest.release'
}
Client-side libraries are packed in this JAR as a WebJars.
Please find the wcardinal.worker.min.js
in the directory META-INF/resources/webjars/wcardinal/${version}/
.
WebJars can be loaded from browsers as follows:
<script src="webjars/wcardinal/wcardinal.worker.min.js"></script>
Please note that the ${version}
part is omitted. The worker version wcardinal.worker.min.js
is strongly recommended over the non-worker version wcardinal.min.js
as the setTimeout
is not reliable in some cases.
NPM
The client-side libraries are also available as a NPM package.
npm i @wcardinal/wcardinal
Please note that the NPM package has no default exports.
import * as wcardinal from '@wcardinal/wcardinal';
CDN
<script src="https://cdn.jsdelivr.net/npm/@wcardinal/wcardinal/dist/wcardinal.worker.min.js"></script>
<script src="./my-controller"></script>
All the classes are in window.wcardinal
in this case.
Note that the wcardinal.worker.min.js
must be loaded before loading your controller as shown above.
Documentation
- API document
- Cheatsheet
- Starter
Compatibility Matrix
|WinterCardinal Version|JDK Version |Spring Boot Version | |-- |-- |-- | |1.0.x |8 |2.2.4.RELEASE | |1.1.0 |8 |2.7.18 | |2.0.0 to 2.1.0 |17 |3.3.1 |
How to build
JS for release
npm run build
JS for development
npm run watch:ts
and then in an another terminal
npm run watch:rollup
Java API document
./gradlew compileJavaApiDocument
JS API document
npm run build:api
Cheatsheet
./gradlew compileCheatsheet
Publishing
JARs to Sonatype
In ~/.gradle/gradle.properties
, add
signing.keyId=<SIGNING-KEYID>
signing.password=<SIGNING-PASSWORD>
signing.secretKeyRingFile=<SIGNING-SECRETRINGFILE>
ossrhUsername=<OSSRH-USERNAME>
ossrhPassword=<OSSRH-PASSWORD>
ossrhName=<OSSRH-NAME>
ossrhEMail=<OSSRH-EMAIL>
ossrhToken=<OSSRH-USER-TOKEN>
ossrhTokenPassword=<OSSRH-USER-TOKEN-PASSWORD>
and then execute
./gradlew publishToSonatype
./gradlew closeAndReleaseRepository
Or close and release via Nexus repository manager.
NPM
npm publish
License
Apache License Version 2.0